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:
parent
7e8ab2118d
commit
afadb98d9d
@ -393,15 +393,15 @@ public class ByteString {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
if (hash != 0) {
|
int h = hash;
|
||||||
return hash;
|
if (h == 0) {
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < value.length; ++i) {
|
for (int i = 0; i < value.length; ++i) {
|
||||||
hash = hash * HASH_CODE_PRIME ^ value[i] & HASH_CODE_PRIME;
|
h = h * HASH_CODE_PRIME ^ value[i] & HASH_CODE_PRIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
return hash;
|
hash = h;
|
||||||
|
}
|
||||||
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user