diff options
author | Rex Kerr <ichoran@gmail.com> | 2014-02-13 15:40:18 -0800 |
---|---|---|
committer | Rex Kerr <ichoran@gmail.com> | 2014-02-14 17:09:52 -0800 |
commit | 326fa9ac4bb96a042733ad5c96ffee163895df5d (patch) | |
tree | c6bcf6e5af9386432404e8f7e6162beec842c798 /src/library/scala/collection/immutable/HashSet.scala | |
parent | c83e01d47d941265fa5415c0f29a884c904fdfa0 (diff) | |
download | scala-326fa9ac4bb96a042733ad5c96ffee163895df5d.tar.gz scala-326fa9ac4bb96a042733ad5c96ffee163895df5d.tar.bz2 scala-326fa9ac4bb96a042733ad5c96ffee163895df5d.zip |
SI-8264 scala.collection.immutable.HashSet#- returns broken Set
Was an error in HashSet's handling of removal of an element when a HashTrieSet should turn into a HashSet1.
Also slightly modified HashMap's filter0 to more closely match HashSet (by adding the same comment).
Diffstat (limited to 'src/library/scala/collection/immutable/HashSet.scala')
-rw-r--r-- | src/library/scala/collection/immutable/HashSet.scala | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/library/scala/collection/immutable/HashSet.scala b/src/library/scala/collection/immutable/HashSet.scala index 67e9d18da7..726937efd9 100644 --- a/src/library/scala/collection/immutable/HashSet.scala +++ b/src/library/scala/collection/immutable/HashSet.scala @@ -431,15 +431,12 @@ object HashSet extends ImmutableSetFactory[HashSet] { case 0 => // the empty set null - case size if size == ks.size => - // We do this check first since even if the result is of size 1 since - // it is preferable to return the existing set for better structural sharing - // we can not rely on ks.- returning the same instance if we subtract an element that is not in it - // so we need to do the size check - this case 1 => // create a new HashSet1 with the hash we already know new HashSet1(ks1.head, hash) + case size if size == ks.size => + // Should only have HSC1 if size > 1 + this case _ => // create a new HashSetCollison with the hash we already know and the new keys new HashSetCollision1(hash, ks1) @@ -861,6 +858,8 @@ object HashSet extends ImmutableSetFactory[HashSet] { new HashTrieSet(bitmapNew, elemsNew, sizeNew) } else null + } else if(elems.length == 1 && !subNew.isInstanceOf[HashTrieSet[_]]) { + subNew } else { val elemsNew = new Array[HashSet[A]](elems.length) Array.copy(elems, 0, elemsNew, 0, elems.length) |