Skip to content

Commit f15f3a2

Browse files
committed
[nomerge] fix performance regression in mutable.HashMap#getOrElseUpdate
the change in question originated in scala/collection-strawman#484. it was correct at the time because `HashTable#addEntry0` has a threshold check but then when the change was backported to 2.12.x in scala/scala#6828, the `HashTable#addEntry0`call was replaced with a call to `HashMap#addEntry0`, which doesn't check the threshold. so if the table is only ever updated using `getOrElseUpdate`, the table's load factor would just keep climbing, resulting in poor performance this was caught by my Project Euler solutions :-) [nomerge] since the problem is specific to the 2.12 code
1 parent b60b3ee commit f15f3a2

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

library/src/scala/collection/mutable/HashMap.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ extends AbstractMap[A, B]
8787
// Repeat search
8888
// because evaluation of `default` can bring entry with `key`
8989
val secondEntry = findEntry(key, newEntryIndex)
90-
if (secondEntry == null) addEntry0(e, newEntryIndex)
90+
if (secondEntry == null) addEntry(e, newEntryIndex)
9191
else secondEntry.value = default
9292
default
9393
}

0 commit comments

Comments
 (0)