Fix for ByteString#hashCode()

Motivation:

ByteString#hashCode() trashes its own hash code if it's being accessed concurrently

Modifications:

Pull the ByteString#hash into a local variable and calculate it locally.

Result:

ByteString#hashCode() is no longer returning a junk value.
This commit is contained in:
Roger Kapsi 2015-04-16 18:27:11 -04:00 committed by Scott Mitchell
parent 7aac50a79a
commit 221a9f50d4

View File

@ -393,15 +393,15 @@ public class ByteString {
@Override
public int hashCode() {
if (hash != 0) {
return hash;
int h = hash;
if (h == 0) {
for (int i = 0; i < value.length; ++i) {
h = h * HASH_CODE_PRIME ^ value[i] & HASH_CODE_PRIME;
}
hash = h;
}
for (int i = 0; i < value.length; ++i) {
hash = hash * HASH_CODE_PRIME ^ value[i] & HASH_CODE_PRIME;
}
return hash;
return h;
}
/**