diff options
author | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-11-17 17:04:12 +0000 |
---|---|---|
committer | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-11-17 17:04:12 +0000 |
commit | eb2d8e39853f776af2c9e2c2d1b479d67641496b (patch) | |
tree | 32826af3eaecca8e95fcff8d35744c1fee6a9b15 /src/library | |
parent | 9266922e1bfcbbebc9b5926864f7e70e49e142e7 (diff) | |
download | scala-eb2d8e39853f776af2c9e2c2d1b479d67641496b.tar.gz scala-eb2d8e39853f776af2c9e2c2d1b479d67641496b.tar.bz2 scala-eb2d8e39853f776af2c9e2c2d1b479d67641496b.zip |
Fixes #3989.
No review.
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/collection/immutable/ListMap.scala | 24 |
1 files changed, 8 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 } |