You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2020/01/06 08:32:11 UTC
[lucene-solr] 02/05: BlockTreeTermsWriter should compute prefix
lengths using Arrays#mismatch. (#1074)
This is an automated email from the ASF dual-hosted git repository.
jpountz pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
commit e810b8c2c5841a0d7ec97e8996fa8d89cdf92389
Author: Adrien Grand <jp...@gmail.com>
AuthorDate: Mon Jan 6 09:02:51 2020 +0100
BlockTreeTermsWriter should compute prefix lengths using Arrays#mismatch. (#1074)
---
.../lucene/codecs/blocktree/BlockTreeTermsWriter.java | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/blocktree/BlockTreeTermsWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/blocktree/BlockTreeTermsWriter.java
index ec3f6e6..c132976 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/blocktree/BlockTreeTermsWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/blocktree/BlockTreeTermsWriter.java
@@ -41,6 +41,7 @@ import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefBuilder;
import org.apache.lucene.util.FixedBitSet;
+import org.apache.lucene.util.FutureArrays;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.IntsRefBuilder;
import org.apache.lucene.util.StringHelper;
@@ -885,18 +886,17 @@ public final class BlockTreeTermsWriter extends FieldsConsumer {
/** Pushes the new term to the top of the stack, and writes new blocks. */
private void pushTerm(BytesRef text) throws IOException {
- int limit = Math.min(lastTerm.length(), text.length);
-
// Find common prefix between last term and current term:
- int pos = 0;
- while (pos < limit && lastTerm.byteAt(pos) == text.bytes[text.offset+pos]) {
- pos++;
+ int prefixLength = FutureArrays.mismatch(lastTerm.bytes(), 0, lastTerm.length(), text.bytes, text.offset, text.offset + text.length);
+ if (prefixLength == -1) { // Only happens for the first term, if it is empty
+ assert lastTerm.length() == 0;
+ prefixLength = 0;
}
// if (DEBUG) System.out.println(" shared=" + pos + " lastTerm.length=" + lastTerm.length);
// Close the "abandoned" suffix now:
- for(int i=lastTerm.length()-1;i>=pos;i--) {
+ for(int i=lastTerm.length()-1;i>=prefixLength;i--) {
// How many items on top of the stack share the current suffix
// we are closing:
@@ -913,7 +913,7 @@ public final class BlockTreeTermsWriter extends FieldsConsumer {
}
// Init new tail:
- for(int i=pos;i<text.length;i++) {
+ for(int i=prefixLength;i<text.length;i++) {
prefixStarts[i] = pending.size();
}