dungba88 commented on code in PR #12710: URL: https://github.com/apache/lucene/pull/12710#discussion_r1368349251
########## lucene/core/src/java/org/apache/lucene/util/fst/IntSequenceOutputs.java: ########## @@ -43,28 +44,29 @@ public IntsRef common(IntsRef output1, IntsRef output2) { assert output1 != null; assert output2 != null; - int pos1 = output1.offset; - int pos2 = output2.offset; - int stopAt1 = pos1 + Math.min(output1.length, output2.length); - while (pos1 < stopAt1) { - if (output1.ints[pos1] != output2.ints[pos2]) { - break; - } - pos1++; - pos2++; - } + int mismatchPos = + Arrays.mismatch( + output1.ints, + output1.offset, + output1.offset + output1.length, + output2.ints, + output2.offset, + output2.offset + output2.length); - if (pos1 == output1.offset) { + if (mismatchPos == 0) { // no common prefix return NO_OUTPUT; - } else if (pos1 == output1.offset + output1.length) { + } else if (mismatchPos == -1) { + // exactly equals + return output1; + } else if (mismatchPos == output1.length) { // output1 is a prefix of output2 return output1; - } else if (pos2 == output2.offset + output2.length) { + } else if (mismatchPos == output2.length) { // output2 is a prefix of output1 return output2; } else { - return new IntsRef(output1.ints, output1.offset, pos1 - output1.offset); + return new IntsRef(output1.ints, output1.offset, mismatchPos); Review Comment: I had a previous comment about this length parameter, but it seems `mismatchPos` will return the relative index, so that's ok. Just added here for posterity. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org