This is an automated email from the ASF dual-hosted git repository.
dmollitor pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/main by this push:
new 9bff3c9e6 AVRO-4049: Use JDK Arrays equal to test if two UTF8 strings
are equal (#3131)
9bff3c9e6 is described below
commit 9bff3c9e65720fbb3268d204c72dfb8c8a0c45b4
Author: belugabehr <[email protected]>
AuthorDate: Sun Sep 22 22:08:58 2024 -0400
AVRO-4049: Use JDK Arrays equal to test if two UTF8 strings are equal
(#3131)
---
lang/java/avro/src/main/java/org/apache/avro/util/Utf8.java | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/lang/java/avro/src/main/java/org/apache/avro/util/Utf8.java
b/lang/java/avro/src/main/java/org/apache/avro/util/Utf8.java
index 9238fd78c..6de9ebb22 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/util/Utf8.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/util/Utf8.java
@@ -158,6 +158,10 @@ public class Utf8 implements Comparable<Utf8>,
CharSequence, Externalizable {
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])