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
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user