@@ -342,7 +342,7 @@ object HashMap extends ImmutableMapFactory[HashMap] with BitOperations.Int {
342
342
}
343
343
344
344
@ deprecatedInheritance(" This class will be made final in a future release." , " 2.12.2" )
345
- class HashMap1 [A ,+ B ](private [collection] val key : A , private [collection] val hash : Int , private [collection] val value : (B @ uV), private [collection ] var kv : (A ,B @ uV)) extends HashMap [A ,B ] {
345
+ class HashMap1 [A ,+ B ](private [collection] val key : A , private [collection] val hash : Int , private [collection] val value : (B @ uV), private [this ] var kvOrNull : (A ,B @ uV)) extends HashMap [A ,B ] {
346
346
override def size = 1
347
347
348
348
private [collection] def getKey = key
@@ -394,8 +394,8 @@ object HashMap extends ImmutableMapFactory[HashMap] with BitOperations.Int {
394
394
override def foreach [U ](f : ((A , B )) => U ): Unit = f(ensurePair)
395
395
override private [immutable] def foreachEntry [U ](f : (A , B ) => U ): Unit = f(key, value)
396
396
// this method may be called multiple times in a multi-threaded environment, but that's ok
397
- private [HashMap ] def ensurePair : (A , B ) = if (kv ne null ) kv else {
398
- kv = (key, value); kv
397
+ private [HashMap ] def ensurePair : (A , B ) = if (kvOrNull ne null ) kvOrNull else {
398
+ kvOrNull = (key, value); kvOrNull
399
399
}
400
400
401
401
protected [HashMap ] override def merge0 [B1 >: B ](that : HashMap [A , B1 ], level : Int , merger : Merger [A , B1 ]): HashMap [A , B1 ] = {
@@ -405,10 +405,10 @@ object HashMap extends ImmutableMapFactory[HashMap] with BitOperations.Int {
405
405
else if (this .hash == hm1.hash && this .key == hm1.key)
406
406
if (merger eq HashMap .defaultMerger) this
407
407
else if (merger eq HashMap .defaultMerger.invert) hm1
408
- else this .updated0(hm1.key, hm1.hash, level, hm1.value, hm1.kv , merger)
409
- else this .updated0(hm1.key, hm1.hash, level, hm1.value, hm1.kv , merger)
408
+ else this .updated0(hm1.key, hm1.hash, level, hm1.value, hm1.ensurePair , merger)
409
+ else this .updated0(hm1.key, hm1.hash, level, hm1.value, hm1.ensurePair , merger)
410
410
case _ =>
411
- that.updated0(key, hash, level, value, kv , merger.invert)
411
+ that.updated0(key, hash, level, value, ensurePair , merger.invert)
412
412
}
413
413
}
414
414
@@ -504,7 +504,7 @@ object HashMap extends ImmutableMapFactory[HashMap] with BitOperations.Int {
504
504
hm.merge0(this , level, merger.invert)
505
505
case h1 : HashMap1 [A , B1 ] =>
506
506
if (h1.hash != hash) makeHashTrieMap(hash, this , h1.hash, h1, level, size + 1 )
507
- else updated0(h1.key, h1.hash, level, h1.value, h1.kv , merger)
507
+ else updated0(h1.key, h1.hash, level, h1.value, h1.ensurePair , merger)
508
508
case c : HashMapCollision1 [A , B1 ] =>
509
509
if (c.hash != hash) makeHashTrieMap(hash, this , c.hash, c, level, c.size + size)
510
510
else if (merger.retainIdentical && (c eq this )) this
@@ -760,7 +760,7 @@ object HashMap extends ImmutableMapFactory[HashMap] with BitOperations.Int {
760
760
761
761
protected [HashMap ] override def merge0 [B1 >: B ](that : HashMap [A , B1 ], level : Int , merger : Merger [A , B1 ]): HashMap [A , B1 ] = that match {
762
762
case hm : HashMap1 [A , B1 ] =>
763
- this .updated0(hm.key, hm.hash, level, hm.value.asInstanceOf [B1 ], hm.kv , merger)
763
+ this .updated0(hm.key, hm.hash, level, hm.value.asInstanceOf [B1 ], hm.ensurePair , merger)
764
764
case that : HashTrieMap [A , B1 ] =>
765
765
def mergeMaybeSubset (larger : HashTrieMap [A , B1 ], smaller : HashTrieMap [A , B1 ], merger : Merger [A , B1 ]): HashTrieMap [A , B1 ] = {
766
766
var resultElems : Array [HashMap [A , B1 ]] = null
0 commit comments