8312164: Refactor Arrays.hashCode for long, boolean, double, float, and Object arrays

Reviewed-by: rriggs, vtewari
This commit is contained in:
Pavel Rappo 2023-07-19 17:21:19 +00:00
parent 14cf035681
commit b5b6f4e7a7

View File

@ -4333,8 +4333,7 @@ public final class Arrays {
} }
int result = 1; int result = 1;
for (long element : a) { for (long element : a) {
int elementHash = (int)(element ^ (element >>> 32)); result = 31 * result + Long.hashCode(element);
result = 31 * result + elementHash;
} }
return result; return result;
} }
@ -4469,7 +4468,7 @@ public final class Arrays {
int result = 1; int result = 1;
for (boolean element : a) for (boolean element : a)
result = 31 * result + (element ? 1231 : 1237); result = 31 * result + Boolean.hashCode(element);
return result; return result;
} }
@ -4496,7 +4495,7 @@ public final class Arrays {
int result = 1; int result = 1;
for (float element : a) for (float element : a)
result = 31 * result + Float.floatToIntBits(element); result = 31 * result + Float.hashCode(element);
return result; return result;
} }
@ -4523,8 +4522,7 @@ public final class Arrays {
int result = 1; int result = 1;
for (double element : a) { for (double element : a) {
long bits = Double.doubleToLongBits(element); result = 31 * result + Double.hashCode(element);
result = 31 * result + (int)(bits ^ (bits >>> 32));
} }
return result; return result;
} }
@ -4557,7 +4555,7 @@ public final class Arrays {
int result = 1; int result = 1;
for (Object element : a) for (Object element : a)
result = 31 * result + (element == null ? 0 : element.hashCode()); result = 31 * result + Objects.hashCode(element);
return result; return result;
} }