Skip to content

Commit 05ab4cf

Browse files
committed
Fix pjwHash64 to generate 64-bit Longs
Previously the constants where set to generate 32-bit ints.
1 parent 3ddfa3c commit 05ab4cf

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

compiler/src/dotty/tools/dotc/core/tasty/TastyPickler.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,19 @@ class TastyPickler(val rootCls: ClassSymbol) {
7575

7676
/** Returns a non-cryptographic 64-bit hash of the array.
7777
*
78-
* from https://en.wikipedia.org/wiki/PJW_hash_function#Implementation
78+
* from https://en.wikipedia.org/wiki/PJW_hash_function#Algorithm
7979
*/
8080
private def pjwHash64(data: Array[Byte]): Long = {
8181
var h = 0L
8282
var i = 0
8383
while (i < data.length) {
8484
val d = data(i) & 0xFFL // Interpret byte as unsigned byte
85-
h = (h << 4) + d
86-
val high = h & 0xF0000000L
87-
if (high != 0)
88-
h ^= high >> 24
89-
h &= ~high
85+
h = (h << 8) + d
86+
val high = h & 0xFF00000000000000L
87+
if (high != 0) {
88+
h ^= high >> 48L
89+
h &= ~high
90+
}
9091
i += 1
9192
}
9293
h

0 commit comments

Comments
 (0)