diff options
author | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-11-17 17:49:28 +0000 |
---|---|---|
committer | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-11-17 17:49:28 +0000 |
commit | 1fbd342a80a1cafbdb3c124cb90862d3713ae3e8 (patch) | |
tree | a94c1ede4db53ef6247cf1c8c50618dfba874658 /src | |
parent | cfa6808a9e965b9b96dbd875a72900af01a192aa (diff) | |
download | scala-1fbd342a80a1cafbdb3c124cb90862d3713ae3e8.tar.gz scala-1fbd342a80a1cafbdb3c124cb90862d3713ae3e8.tar.bz2 scala-1fbd342a80a1cafbdb3c124cb90862d3713ae3e8.zip |
Another fix for #3989, regarding the `-` which ...
Another fix for #3989, regarding the `-` which also used to cause stack
overflows. No review.
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/collection/immutable/ListMap.scala | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/src/library/scala/collection/immutable/ListMap.scala b/src/library/scala/collection/immutable/ListMap.scala index 61cee12c13..28d2f637db 100644 --- a/src/library/scala/collection/immutable/ListMap.scala +++ b/src/library/scala/collection/immutable/ListMap.scala @@ -183,14 +183,32 @@ 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] = - if (k == key) - next - else { - val tail = next - k - if (tail eq next) this - else new tail.Node(key, value) + override def - (k: A): ListMap[A, B1] = { + // This definition used to result in stack overflows + // if (k == key) + // next + // else { + // val tail = next - k + // if (tail eq next) this + // else new tail.Node(key, value) + // } + // we use an imperative one instead: + var cur: ListMap[A, B1] = this + var lst: List[(A, B1)] = Nil + while (cur.nonEmpty) { + if (k != cur.key) lst ::= ((cur.key, cur.value)) + cur = cur.next } + var acc = ListMap[A, B1]() + while (lst != Nil) { + val elem = lst.head + val stbl = acc + acc = new stbl.Node(elem._1, elem._2) + lst = lst.tail + } + acc + } + override protected def next: ListMap[A, B1] = ListMap.this } |