Skip to content

Commit 9bff3c9

Browse files
authored
AVRO-4049: Use JDK Arrays equal to test if two UTF8 strings are equal (#3131)
1 parent 599be18 commit 9bff3c9

File tree

1 file changed

+4
-0
lines changed
  • lang/java/avro/src/main/java/org/apache/avro/util

1 file changed

+4
-0
lines changed

lang/java/avro/src/main/java/org/apache/avro/util/Utf8.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ public boolean equals(Object o) {
158158
Utf8 that = (Utf8) o;
159159
if (!(this.length == that.length))
160160
return false;
161+
// For longer strings, leverage vectorization (JDK 9+) to determine equality
162+
// For shorter strings, the overhead of this method defeats the value
163+
if (this.length > 7)
164+
return Arrays.equals(this.bytes, 0, this.length, that.bytes, 0, that.length);
161165
byte[] thatBytes = that.bytes;
162166
for (int i = 0; i < this.length; i++)
163167
if (bytes[i] != thatBytes[i])

0 commit comments

Comments
 (0)