Skip to content

Commit 8d4122f

Browse files
committed
Align immutable.{MapN,HashMap} key/value handling with 2.13.x
Fix these properties: ``` checkAllValuesUpdated(gen, "++ (identical key)")(_.++(Seq((Value(1,1), Value(101,2)))).filter(_._1.id == 1)) checkAllValuesUpdated(gen, "++ (identical key)")(_.++(Seq((Value(1,1), Value(101,2)))).filter(_._1.id == 1)) ``` Unskip immutable.HashMap
1 parent 549d98e commit 8d4122f

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

library/src/scala/collection/immutable/HashMap.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ object HashMap extends ImmutableMapFactory[HashMap] with BitOperations.Int {
366366
if (key == this.key) {
367367
if (merger eq null) {
368368
if (this.value.asInstanceOf[AnyRef] eq value.asInstanceOf[AnyRef]) this
369-
else new HashMap1(key, hash, value, kv)
369+
else new HashMap1(this.key, hash, value, null)
370370
} else if (
371371
(key.asInstanceOf[AnyRef] eq this.key.asInstanceOf[AnyRef]) &&
372372
(value.asInstanceOf[AnyRef] eq this.value.asInstanceOf[AnyRef]) &&
@@ -556,7 +556,6 @@ object HashMap extends ImmutableMapFactory[HashMap] with BitOperations.Int {
556556
private[HashMap] var elems0: Array[HashMap[A, B @uV]],
557557
private[HashMap] var size0: Int
558558
) extends HashMap[A, B @uV] {
559-
560559
@inline private[collection] final def bitmap: Int = bitmap0
561560
@inline private[collection] final def elems: Array[HashMap[A, B @uV]] = elems0
562561

library/src/scala/collection/immutable/Map.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -621,12 +621,15 @@ object Map extends ImmutableMapFactory[Map] {
621621
} else if (elems.size < 4) {
622622
elems = elems + elem
623623
} else {
624-
// assert(elems.size == 4)
625-
elems.get(elem._1) match {
626-
case Some(x) if x == elem._2 => ()
627-
case _ =>
628-
convertToHashMapBuilder()
629-
hashMapBuilder += elem
624+
val key = elem._1
625+
val newValue = elem._2
626+
elems.getOrElse(key, Sentinel) match {
627+
case Sentinel =>
628+
convertToHashMapBuilder()
629+
hashMapBuilder += elem
630+
case existingValue =>
631+
if (existingValue.asInstanceOf[AnyRef] ne newValue.asInstanceOf[AnyRef])
632+
elems = elems + elem
630633
}
631634
}
632635
this
@@ -646,6 +649,7 @@ object Map extends ImmutableMapFactory[Map] {
646649
this
647650
}
648651
}
652+
private val Sentinel = new Object
649653
}
650654

651655
/** Explicit instantiation of the `Map` trait to reduce class file size in subclasses. */

0 commit comments

Comments
 (0)