summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksandar Pokopec <aleksandar.prokopec@epfl.ch>2010-11-17 17:04:12 +0000
committerAleksandar Pokopec <aleksandar.prokopec@epfl.ch>2010-11-17 17:04:12 +0000
commiteb2d8e39853f776af2c9e2c2d1b479d67641496b (patch)
tree32826af3eaecca8e95fcff8d35744c1fee6a9b15
parent9266922e1bfcbbebc9b5926864f7e70e49e142e7 (diff)
downloadscala-eb2d8e39853f776af2c9e2c2d1b479d67641496b.tar.gz
scala-eb2d8e39853f776af2c9e2c2d1b479d67641496b.tar.bz2
scala-eb2d8e39853f776af2c9e2c2d1b479d67641496b.zip
Fixes #3989.
No review.
-rw-r--r--src/library/scala/collection/immutable/ListMap.scala24
-rw-r--r--test/files/run/t3989.scala1
-rw-r--r--test/files/run/t3996.scala1
3 files changed, 10 insertions, 16 deletions
diff --git a/src/library/scala/collection/immutable/ListMap.scala b/src/library/scala/collection/immutable/ListMap.scala
index 4b7e512e47..61cee12c13 100644
--- a/src/library/scala/collection/immutable/ListMap.scala
+++ b/src/library/scala/collection/immutable/ListMap.scala
@@ -183,22 +183,14 @@ class ListMap[A, +B] extends Map[A, B] with MapLike[A, B, ListMap[A, B]] {
* @param k ...
* @return ...
*/
- override def - (k: A): ListMap[A, B1] = remove0(this, k, ListMap[A, B1]())
-
- // this solution was nicer and possibly more efficient, but resulted in stack overflows:
- // if (k == key)
- // next
- // else {
- // val tail = next - k
- // if (tail eq next) this
- // else new tail.Node(key, value)
- // }
-
- @tailrec private def remove0(cur: ListMap[A, B1], k: A, acc: ListMap[A, B1]): ListMap[A, B1] =
- if (cur.nonEmpty) {
- if (k == cur.key) remove0(cur.next, k, acc)
- else remove0(cur.next, k, new acc.Node(cur.key, cur.value))
- } else cur
+ override def - (k: A): ListMap[A, B1] =
+ if (k == key)
+ next
+ else {
+ val tail = next - k
+ if (tail eq next) this
+ else new tail.Node(key, value)
+ }
override protected def next: ListMap[A, B1] = ListMap.this
}
diff --git a/test/files/run/t3989.scala b/test/files/run/t3989.scala
index d519978e54..0daa8abee3 100644
--- a/test/files/run/t3989.scala
+++ b/test/files/run/t3989.scala
@@ -5,6 +5,7 @@
class Foo{ override def equals(o: Any) = false; override def hashCode = 1}
+// should not result in a stack overflow
object Test {
def main(args: Array[String]) {
import collection.immutable.HashMap
diff --git a/test/files/run/t3996.scala b/test/files/run/t3996.scala
index 1bb1216390..e6e5549cfa 100644
--- a/test/files/run/t3996.scala
+++ b/test/files/run/t3996.scala
@@ -3,6 +3,7 @@
+// should not result in a stack overflow
object Test {
def main(args: Array[String]) {
import collection.mutable.LinkedList