Skip to content

Commit 000b432

Browse files
committed
Implement TastyHash based on PJW hash.
1 parent eed4b9b commit 000b432

File tree

2 files changed

+21
-225
lines changed

2 files changed

+21
-225
lines changed

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

Lines changed: 21 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,23 @@ 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+
var i = 0
83+
while (i < data.length) {
84+
h = (h << 4) + data(i)
85+
high = h & 0xF0000000L
86+
if (high != 0)
87+
h ^= high >> 24
88+
h &= ~high
89+
i += 1
90+
}
91+
h
92+
}
7593
}

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

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

0 commit comments

Comments
 (0)