From 5727b8ce591cc5d63e080eb92476da346f2507a3 Mon Sep 17 00:00:00 2001 From: zhouhui Date: Tue, 15 Oct 2024 22:12:48 +0800 Subject: [PATCH] Optimize convert byte2int. (#13889) --- lucene/core/src/java/org/apache/lucene/util/fst/Util.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/util/fst/Util.java b/lucene/core/src/java/org/apache/lucene/util/fst/Util.java index a6df78eaab5..c0f4bfeb572 100644 --- a/lucene/core/src/java/org/apache/lucene/util/fst/Util.java +++ b/lucene/core/src/java/org/apache/lucene/util/fst/Util.java @@ -775,10 +775,11 @@ public final class Util { /** Just takes unsigned byte values from the BytesRef and converts into an IntsRef. */ public static IntsRef toIntsRef(BytesRef input, IntsRefBuilder scratch) { - scratch.clear(); + scratch.growNoCopy(input.length); for (int i = 0; i < input.length; i++) { - scratch.append(input.bytes[i + input.offset] & 0xFF); + scratch.setIntAt(i, input.bytes[i + input.offset] & 0xFF); } + scratch.setLength(input.length); return scratch.get(); }