Skip to content

Commit b5b6f4e

Browse files
author
Pavel Rappo
committed
8312164: Refactor Arrays.hashCode for long, boolean, double, float, and Object arrays
Reviewed-by: rriggs, vtewari
1 parent 14cf035 commit b5b6f4e

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/java.base/share/classes/java/util/Arrays.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -4333,8 +4333,7 @@ public static int hashCode(long[] a) {
43334333
}
43344334
int result = 1;
43354335
for (long element : a) {
4336-
int elementHash = (int)(element ^ (element >>> 32));
4337-
result = 31 * result + elementHash;
4336+
result = 31 * result + Long.hashCode(element);
43384337
}
43394338
return result;
43404339
}
@@ -4469,7 +4468,7 @@ public static int hashCode(boolean[] a) {
44694468

44704469
int result = 1;
44714470
for (boolean element : a)
4472-
result = 31 * result + (element ? 1231 : 1237);
4471+
result = 31 * result + Boolean.hashCode(element);
44734472

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

44974496
int result = 1;
44984497
for (float element : a)
4499-
result = 31 * result + Float.floatToIntBits(element);
4498+
result = 31 * result + Float.hashCode(element);
45004499

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

45244523
int result = 1;
45254524
for (double element : a) {
4526-
long bits = Double.doubleToLongBits(element);
4527-
result = 31 * result + (int)(bits ^ (bits >>> 32));
4525+
result = 31 * result + Double.hashCode(element);
45284526
}
45294527
return result;
45304528
}
@@ -4557,7 +4555,7 @@ public static int hashCode(Object[] a) {
45574555
int result = 1;
45584556

45594557
for (Object element : a)
4560-
result = 31 * result + (element == null ? 0 : element.hashCode());
4558+
result = 31 * result + Objects.hashCode(element);
45614559

45624560
return result;
45634561
}

0 commit comments

Comments
 (0)