mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8332826: Make hashCode methods in ArraysSupport friendlier
Reviewed-by: redestad, liach
This commit is contained in:
parent
2b4a4b7bd8
commit
3cff588a31
13 changed files with 234 additions and 80 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -4358,11 +4358,7 @@ public final class Arrays {
|
|||
if (a == null) {
|
||||
return 0;
|
||||
}
|
||||
return switch (a.length) {
|
||||
case 0 -> 1;
|
||||
case 1 -> 31 + a[0];
|
||||
default -> ArraysSupport.vectorizedHashCode(a, 0, a.length, 1, ArraysSupport.T_INT);
|
||||
};
|
||||
return ArraysSupport.hashCode(a, 0, a.length, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4385,11 +4381,7 @@ public final class Arrays {
|
|||
if (a == null) {
|
||||
return 0;
|
||||
}
|
||||
return switch (a.length) {
|
||||
case 0 -> 1;
|
||||
case 1 -> 31 + (int)a[0];
|
||||
default -> ArraysSupport.vectorizedHashCode(a, 0, a.length, 1, ArraysSupport.T_SHORT);
|
||||
};
|
||||
return ArraysSupport.hashCode(a, 0, a.length, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4412,11 +4404,7 @@ public final class Arrays {
|
|||
if (a == null) {
|
||||
return 0;
|
||||
}
|
||||
return switch (a.length) {
|
||||
case 0 -> 1;
|
||||
case 1 -> 31 + (int)a[0];
|
||||
default -> ArraysSupport.vectorizedHashCode(a, 0, a.length, 1, ArraysSupport.T_CHAR);
|
||||
};
|
||||
return ArraysSupport.hashCode(a, 0, a.length, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4439,11 +4427,7 @@ public final class Arrays {
|
|||
if (a == null) {
|
||||
return 0;
|
||||
}
|
||||
return switch (a.length) {
|
||||
case 0 -> 1;
|
||||
case 1 -> 31 + (int)a[0];
|
||||
default -> ArraysSupport.vectorizedHashCode(a, 0, a.length, 1, ArraysSupport.T_BYTE);
|
||||
};
|
||||
return ArraysSupport.hashCode(a, 0, a.length, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4549,15 +4533,10 @@ public final class Arrays {
|
|||
* @since 1.5
|
||||
*/
|
||||
public static int hashCode(Object[] a) {
|
||||
if (a == null)
|
||||
if (a == null) {
|
||||
return 0;
|
||||
|
||||
int result = 1;
|
||||
|
||||
for (Object element : a)
|
||||
result = 31 * result + Objects.hashCode(element);
|
||||
|
||||
return result;
|
||||
}
|
||||
return ArraysSupport.hashCode(a, 0, a.length, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -290,8 +290,7 @@ class ZipCoder {
|
|||
// exceptions eagerly when opening ZipFiles
|
||||
return hash(JLA.newStringUTF8NoRepl(a, off, len));
|
||||
}
|
||||
// T_BOOLEAN to treat the array as unsigned bytes, in line with StringLatin1.hashCode
|
||||
int h = ArraysSupport.vectorizedHashCode(a, off, len, 0, ArraysSupport.T_BOOLEAN);
|
||||
int h = ArraysSupport.hashCodeOfUnsigned(a, off, len, 0);
|
||||
if (a[end - 1] != '/') {
|
||||
h = 31 * h + '/';
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue