Skip to content

Apache Lucene open-source search software

Rewrite the copying loop slightly; scratch.grow has an assert offset == 0 so moved this reset up before grow.

Dawid Weiss00f61eb9cbc3
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 7a9685745ed..0dbc7966eb5 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
@@ -771,16 +771,14 @@ public final class Util {
* IntsRef. */
public static IntsRef toUTF16(CharSequence s, IntsRef scratch) {
final int charLimit = s.length();
+ scratch.offset = 0;
+ scratch.length = charLimit;
scratch.grow(charLimit);
- int idx = 0;
- while(idx < charLimit) {
+ for (int idx = 0; idx < charLimit; idx++) {
scratch.ints[idx] = (int) s.charAt(idx);
- idx++;
}
- scratch.offset = 0;
- scratch.length = idx;
return scratch;
- }
+ }
/** Decodes the Unicode codepoints from the provided
* CharSequence and places them in the provided scratch