Skip to content

Commit

Permalink
8312164: Refactor Arrays.hashCode for long, boolean, double, float, a…
Browse files Browse the repository at this point in the history
…nd Object arrays

Reviewed-by: rriggs, vtewari
  • Loading branch information
pavelrappo committed Jul 19, 2023
1 parent 14cf035 commit b5b6f4e
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/java.base/share/classes/java/util/Arrays.java
Original file line number Diff line number Diff line change
Expand Up @@ -4333,8 +4333,7 @@ public static int hashCode(long[] a) {
}
int result = 1;
for (long element : a) {
int elementHash = (int)(element ^ (element >>> 32));
result = 31 * result + elementHash;
result = 31 * result + Long.hashCode(element);
}
return result;
}
Expand Down Expand Up @@ -4469,7 +4468,7 @@ public static int hashCode(boolean[] a) {

int result = 1;
for (boolean element : a)
result = 31 * result + (element ? 1231 : 1237);
result = 31 * result + Boolean.hashCode(element);

return result;
}
Expand All @@ -4496,7 +4495,7 @@ public static int hashCode(float[] a) {

int result = 1;
for (float element : a)
result = 31 * result + Float.floatToIntBits(element);
result = 31 * result + Float.hashCode(element);

return result;
}
Expand All @@ -4523,8 +4522,7 @@ public static int hashCode(double[] a) {

int result = 1;
for (double element : a) {
long bits = Double.doubleToLongBits(element);
result = 31 * result + (int)(bits ^ (bits >>> 32));
result = 31 * result + Double.hashCode(element);
}
return result;
}
Expand Down Expand Up @@ -4557,7 +4555,7 @@ public static int hashCode(Object[] a) {
int result = 1;

for (Object element : a)
result = 31 * result + (element == null ? 0 : element.hashCode());
result = 31 * result + Objects.hashCode(element);

return result;
}
Expand Down

0 comments on commit b5b6f4e

Please sign in to comment.