Skip to content

Commit 1f67c00

Browse files
authored
Merge pull request #3768 from dotty-staging/fix-#1619
Fix #1619: Reduce collision rate in NameTable
2 parents 36abda9 + 53cb026 commit 1f67c00

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
@@ -546,13 +546,15 @@ object Names {
546546
private[this] var size = 1
547547

548548
/** The hash of a name made of from characters cs[offset..offset+len-1]. */
549-
private def hashValue(cs: Array[Char], offset: Int, len: Int): Int =
550-
if (len > 0)
551-
(len * (41 * 41 * 41) +
552-
cs(offset) * (41 * 41) +
553-
cs(offset + len - 1) * 41 +
554-
cs(offset + (len >> 1)))
555-
else 0
549+
private def hashValue(cs: Array[Char], offset: Int, len: Int): Int = {
550+
var i = offset
551+
var hash = 0
552+
while (i < len + offset) {
553+
hash = 31 * hash + cs(i)
554+
i += 1
555+
}
556+
hash
557+
}
556558

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

0 commit comments

Comments
 (0)