diff options
author | Ruediger Klaehn <rklaehn@gmail.com> | 2014-01-20 21:37:21 +0100 |
---|---|---|
committer | Ruediger Klaehn <rklaehn@gmail.com> | 2014-01-20 23:42:16 +0100 |
commit | 7f65b37a30cb0162711e3889edd35b2608ffa729 (patch) | |
tree | a02c7fc1bad6ddb5e5f15b9435eb8bff8f51cc59 /src/library/scala/collection/immutable/HashMap.scala | |
parent | 8f6f4032b5c026fd9301cebe28dde5bb7c8e264c (diff) | |
download | scala-7f65b37a30cb0162711e3889edd35b2608ffa729.tar.gz scala-7f65b37a30cb0162711e3889edd35b2608ffa729.tar.bz2 scala-7f65b37a30cb0162711e3889edd35b2608ffa729.zip |
SI-7445 ListMap.tail is returning wrong result
Reverted the commit that introduced the bug, and modified HashMap to no
longer assume that tail is O(1).
Review by @Ichoran, @soc
Diffstat (limited to 'src/library/scala/collection/immutable/HashMap.scala')
-rw-r--r-- | src/library/scala/collection/immutable/HashMap.scala | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/library/scala/collection/immutable/HashMap.scala b/src/library/scala/collection/immutable/HashMap.scala index e7d87dd3fe..8a24f721d7 100644 --- a/src/library/scala/collection/immutable/HashMap.scala +++ b/src/library/scala/collection/immutable/HashMap.scala @@ -247,15 +247,17 @@ object HashMap extends ImmutableMapFactory[HashMap] with BitOperations.Int { override def removed0(key: A, hash: Int, level: Int): HashMap[A, B] = if (hash == this.hash) { val kvs1 = kvs - key - if (kvs1 eq kvs) - this - else if (kvs1.isEmpty) - HashMap.empty[A,B] - else if(kvs1.tail.isEmpty) { - val kv = kvs1.head - new HashMap1[A,B](kv._1,hash,kv._2,kv) - } else - new HashMapCollision1(hash, kvs1) + kvs1.size match { + case 0 => + HashMap.empty[A,B] + case 1 => + val kv = kvs1.head + new HashMap1(kv._1,hash,kv._2,kv) + case x if x == kvs.size => + this + case _ => + new HashMapCollision1(hash, kvs1) + } } else this override protected def filter0(p: ((A, B)) => Boolean, negate: Boolean, level: Int, buffer: Array[HashMap[A, B @uV]], offset0: Int): HashMap[A, B] = { |