Skip to content

Commit 426a33a

Browse files
committed
Implement TastyHash based on PJW hash.
1 parent c73fd4b commit 426a33a

File tree

2 files changed

+19
-225
lines changed

2 files changed

+19
-225
lines changed

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package tasty
66
import TastyFormat._
77
import collection.mutable
88
import TastyBuffer._
9-
import util.CityHash
109
import core.Symbols.Symbol
1110
import ast.tpd
1211
import Decorators._
@@ -26,8 +25,8 @@ class TastyPickler {
2625
buf.length + natSize(buf.length)
2726
}
2827

29-
val uuidLow: Long = CityHash.bytesHash(nameBuffer.bytes)
30-
val uuidHi: Long = sections.iterator.map(x => CityHash.bytesHash(x._2.bytes)).fold(0L)(_ ^ _)
28+
val uuidLow: Long = pjwHash64(nameBuffer.bytes)
29+
val uuidHi: Long = sections.iterator.map(x => pjwHash64(x._2.bytes)).fold(0L)(_ ^ _)
3130

3231
val headerBuffer = {
3332
val buf = new TastyBuffer(header.length + 24)
@@ -72,4 +71,21 @@ class TastyPickler {
7271
var addrOfSym: Symbol => Option[Addr] = (_ => None)
7372

7473
val treePkl = new TreePickler(this)
74+
75+
/** Returns a non-cryptographic 64-bit hash of the array.
76+
*
77+
* from https://en.wikipedia.org/wiki/PJW_hash_function#Implementation
78+
*/
79+
private def pjwHash64(data: Array[Byte]): Long = {
80+
var h = 0L
81+
var high = 0L
82+
for (b <- data) {
83+
h = (h << 4) + b
84+
high = h & 0xF0000000L
85+
if (high != 0)
86+
h ^= high >> 24
87+
h &= ~high
88+
}
89+
h
90+
}
7591
}

compiler/src/dotty/tools/dotc/util/CityHash.scala

Lines changed: 0 additions & 222 deletions
This file was deleted.

0 commit comments

Comments
 (0)