Skip to content

Commit 9078f29

Browse files
committed
Fix #1619: Reduce collision rate in NameTable
The fix is consistent with Scalac: https://github.com/scala/scala/pull/5474/files.
1 parent 098c50a commit 9078f29

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

compiler/src/dotty/tools/dotc/core/Names.scala

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,15 @@ object Names {
221221
private var size = 1
222222

223223
/** The hash of a name made of from characters cs[offset..offset+len-1]. */
224-
private def hashValue(cs: Array[Char], offset: Int, len: Int): Int =
225-
if (len > 0)
226-
(len * (41 * 41 * 41) +
227-
cs(offset) * (41 * 41) +
228-
cs(offset + len - 1) * 41 +
229-
cs(offset + (len >> 1)))
230-
else 0
224+
private def hashValue(cs: Array[Char], offset: Int, len: Int): Int = {
225+
var i = offset
226+
var hash = 0
227+
while (i < len + offset) {
228+
hash = 31 * hash + cs(i)
229+
i += 1
230+
}
231+
hash
232+
}
231233

232234
/** Is (the ASCII representation of) name at given index equal to
233235
* cs[offset..offset+len-1]?

0 commit comments

Comments
 (0)