Skip to content

Commit

Permalink
AVRO-4049: Use JDK Arrays equal to test if two UTF8 strings are equal (
Browse files Browse the repository at this point in the history
  • Loading branch information
belugabehr authored Sep 23, 2024
1 parent 599be18 commit 9bff3c9
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 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 @@ -158,6 +158,10 @@ public boolean equals(Object o) {
Utf8 that = (Utf8) o;
if (!(this.length == that.length))
return false;
// For longer strings, leverage vectorization (JDK 9+) to determine equality
// For shorter strings, the overhead of this method defeats the value
if (this.length > 7)
return Arrays.equals(this.bytes, 0, this.length, that.bytes, 0, that.length);
byte[] thatBytes = that.bytes;
for (int i = 0; i < this.length; i++)
if (bytes[i] != thatBytes[i])
Expand Down

0 comments on commit 9bff3c9

Please # to comment.