mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8221723: Avoid storing zero to String.hash
Reviewed-by: shade, prappo, jiangli
This commit is contained in:
parent
6bce53795b
commit
1908897b93
2 changed files with 20 additions and 3 deletions
|
@ -1510,8 +1510,14 @@ public final class String
|
|||
public int hashCode() {
|
||||
int h = hash;
|
||||
if (h == 0 && value.length > 0) {
|
||||
hash = h = isLatin1() ? StringLatin1.hashCode(value)
|
||||
: StringUTF16.hashCode(value);
|
||||
h = isLatin1() ? StringLatin1.hashCode(value)
|
||||
: StringUTF16.hashCode(value);
|
||||
// Avoid issuing a store if the calculated value is also zero:
|
||||
// in addition to a minor performance benefit, this allows storing
|
||||
// Strings with zero hash code in read-only memory.
|
||||
if (h != 0) {
|
||||
hash = h;
|
||||
}
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue