File tree Expand file tree Collapse file tree 2 files changed +11
-8
lines changed
library/src/scala/collection/immutable Expand file tree Collapse file tree 2 files changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -366,7 +366,7 @@ object HashMap extends ImmutableMapFactory[HashMap] with BitOperations.Int {
366
366
if (key == this .key) {
367
367
if (merger eq null ) {
368
368
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 )
370
370
} else if (
371
371
(key.asInstanceOf [AnyRef ] eq this .key.asInstanceOf [AnyRef ]) &&
372
372
(value.asInstanceOf [AnyRef ] eq this .value.asInstanceOf [AnyRef ]) &&
@@ -556,7 +556,6 @@ object HashMap extends ImmutableMapFactory[HashMap] with BitOperations.Int {
556
556
private [HashMap ] var elems0 : Array [HashMap [A , B @ uV]],
557
557
private [HashMap ] var size0 : Int
558
558
) extends HashMap [A , B @ uV] {
559
-
560
559
@ inline private [collection] final def bitmap : Int = bitmap0
561
560
@ inline private [collection] final def elems : Array [HashMap [A , B @ uV]] = elems0
562
561
Original file line number Diff line number Diff line change @@ -621,12 +621,15 @@ object Map extends ImmutableMapFactory[Map] {
621
621
} else if (elems.size < 4 ) {
622
622
elems = elems + elem
623
623
} 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
630
633
}
631
634
}
632
635
this
@@ -646,6 +649,7 @@ object Map extends ImmutableMapFactory[Map] {
646
649
this
647
650
}
648
651
}
652
+ private val Sentinel = new Object
649
653
}
650
654
651
655
/** Explicit instantiation of the `Map` trait to reduce class file size in subclasses. */
You can’t perform that action at this time.
0 commit comments