Skip to content

Commit

Permalink
Use Arrays.mismatch in FSTCompiler#add. (#13924)
Browse files Browse the repository at this point in the history
  • Loading branch information
vsop-479 authored Dec 1, 2024
1 parent be66af2 commit a248306
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lucene/core/src/java/org/apache/lucene/util/fst/FSTCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static org.apache.lucene.util.fst.FST.getNumPresenceBytes;

import java.io.IOException;
import java.util.Arrays;
import java.util.Objects;
import org.apache.lucene.store.ByteArrayDataOutput;
import org.apache.lucene.store.DataOutput;
Expand Down Expand Up @@ -869,14 +870,14 @@ public void add(IntsRef input, T output) throws IOException {
}

// compare shared prefix length
int pos1 = 0;
int pos2 = input.offset;
final int pos1Stop = Math.min(lastInput.length(), input.length);
while (pos1 < pos1Stop && lastInput.intAt(pos1) == input.ints[pos2]) {
pos1++;
pos2++;
int pos = 0;
if (lastInput.length() > 0) {
int mismatch =
Arrays.mismatch(
lastInput.ints(), 0, lastInput.length(), input.ints, input.offset, input.length);
pos += mismatch == -1 ? lastInput.length() : mismatch;
}
final int prefixLenPlus1 = pos1 + 1;
final int prefixLenPlus1 = pos + 1;

if (frontier.length < input.length + 1) {
final UnCompiledNode<T>[] next = ArrayUtil.grow(frontier, input.length + 1);
Expand Down

0 comments on commit a248306

Please sign in to comment.