Rewrite the copying loop slightly; scratch.grow has an assert offset == 0

so moved this reset up before grow.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1374431 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dawid Weiss 2012-08-17 20:46:16 +00:00
parent 9a00dbc928
commit 00f61eb9cb
1 changed files with 6 additions and 8 deletions
lucene/core/src/java/org/apache/lucene/util/fst

View File

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