From 9bff3c9e65720fbb3268d204c72dfb8c8a0c45b4 Mon Sep 17 00:00:00 2001 From: belugabehr <12578579+belugabehr@users.noreply.github.com> Date: Sun, 22 Sep 2024 22:08:58 -0400 Subject: [PATCH] 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 9238fd78c65..6de9ebb22c5 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 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])