Skip to content

Commit a193d5a

Browse files
authored
Merge pull request scala/scala#8898 from mkeskells/2.12.x_HashMapBuilderBug
HashMapBuilder bug fix
2 parents 35910d2 + d3f209e commit a193d5a

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,17 +1295,23 @@ object HashMap extends ImmutableMapFactory[HashMap] with BitOperations.Int {
12951295
var bArrayIndex = 0
12961296
while (bBitSet != 0) {
12971297
val rawIndex = Integer.numberOfTrailingZeros(bBitSet)
1298-
val aValue = result.elems(trieIndex(result, rawIndex))
1298+
val arrayIndex = trieIndex(result, rawIndex)
12991299
val bValue = bTrie.elems(bArrayIndex)
1300-
if (aValue ne bValue) {
1301-
if (aValue eq null) {
1302-
assert (isMutable(result))
1303-
result.elems(rawIndex) = bValue
1304-
} else {
1305-
val resultAtIndex = addHashMap(aValue, bValue, level + 5)
1306-
if (resultAtIndex ne aValue) {
1307-
result = makeMutable(result)
1308-
result.elems(rawIndex) = resultAtIndex
1300+
if (arrayIndex == -1) {
1301+
result = makeMutable(result)
1302+
result.elems(rawIndex) = bValue
1303+
} else {
1304+
val aValue = result.elems(arrayIndex)
1305+
if (aValue ne bValue) {
1306+
if (aValue eq null) {
1307+
assert(isMutable(result))
1308+
result.elems(rawIndex) = bValue
1309+
} else {
1310+
val resultAtIndex = addHashMap(aValue, bValue, level + 5)
1311+
if (resultAtIndex ne aValue) {
1312+
result = makeMutable(result)
1313+
result.elems(rawIndex) = resultAtIndex
1314+
}
13091315
}
13101316
}
13111317
}

0 commit comments

Comments
 (0)