Skip to content

Commit

Permalink
AVRO-4060: Use JDK to Hash Byte Array in UTF8
Browse files Browse the repository at this point in the history
  • Loading branch information
belugabehr committed Sep 25, 2024
1 parent 005ee80 commit eba2337
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lang/java/avro/src/main/java/org/apache/avro/util/Utf8.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,14 @@ public int hashCode() {
if (h == 0) {
byte[] bytes = this.bytes;
int length = this.length;
for (int i = 0; i < length; i++) {
h = h * 31 + bytes[i];
// If the array is filled, use the underlying JDK hash functionality.
// Starting with JDK 21, the underlying implementation is vectorized.
if (bytes.length == length) {
h = Arrays.hashCode(bytes);
} else {
for (int i = 0; i < length; i++) {
h = h * 31 + bytes[i];
}
}
this.hash = h;
}
Expand Down

0 comments on commit eba2337

Please # to comment.