You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2014/07/24 22:16:56 UTC
svn commit: r1613268 - in /lucene/dev/trunk/lucene:
codecs/src/java/org/apache/lucene/codecs/blocktreeords/
core/src/java/org/apache/lucene/codecs/blocktree/
sandbox/src/java/org/apache/lucene/codecs/idversion/
Author: mikemccand
Date: Thu Jul 24 20:16:56 2014
New Revision: 1613268
URL: http://svn.apache.org/r1613268
Log:
LUCENE-5610: optimization: just use already allocated/copied PendingTerm to for min/maxTerm
Modified:
lucene/dev/trunk/lucene/codecs/src/java/org/apache/lucene/codecs/blocktreeords/OrdsBlockTreeTermsWriter.java
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/codecs/blocktree/BlockTreeTermsWriter.java
lucene/dev/trunk/lucene/sandbox/src/java/org/apache/lucene/codecs/idversion/VersionBlockTreeTermsWriter.java
Modified: lucene/dev/trunk/lucene/codecs/src/java/org/apache/lucene/codecs/blocktreeords/OrdsBlockTreeTermsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/codecs/src/java/org/apache/lucene/codecs/blocktreeords/OrdsBlockTreeTermsWriter.java?rev=1613268&r1=1613267&r2=1613268&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/codecs/src/java/org/apache/lucene/codecs/blocktreeords/OrdsBlockTreeTermsWriter.java (original)
+++ lucene/dev/trunk/lucene/codecs/src/java/org/apache/lucene/codecs/blocktreeords/OrdsBlockTreeTermsWriter.java Thu Jul 24 20:16:56 2014
@@ -239,21 +239,15 @@ public final class OrdsBlockTreeTermsWri
TermsEnum termsEnum = terms.iterator(null);
TermsWriter termsWriter = new TermsWriter(fieldInfos.fieldInfo(field));
- BytesRef minTerm = null;
- BytesRef maxTerm = new BytesRef();
while (true) {
BytesRef term = termsEnum.next();
if (term == null) {
break;
}
- if (minTerm == null) {
- minTerm = BytesRef.deepCopyOf(term);
- }
- maxTerm.copyBytes(term);
termsWriter.write(term, termsEnum);
}
- termsWriter.finish(minTerm, minTerm == null ? null : maxTerm);
+ termsWriter.finish();
}
}
@@ -464,13 +458,16 @@ public final class OrdsBlockTreeTermsWri
// Pending stack of terms and blocks. As terms arrive (in sorted order)
// we append to this stack, and once the top of the stack has enough
- // terms starting with a common prefix, write write a new block with
+ // terms starting with a common prefix, we write a new block with
// those terms and replace those terms in the stack with a new block:
private final List<PendingEntry> pending = new ArrayList<>();
// Reused in writeBlocks:
private final List<PendingBlock> newBlocks = new ArrayList<>();
+ private PendingTerm firstPendingTerm;
+ private PendingTerm lastPendingTerm;
+
/** Writes the top count entries in pending, using prevTerm to compute the prefix. */
void writeBlocks(int prefixLength, int count) throws IOException {
@@ -812,6 +809,10 @@ public final class OrdsBlockTreeTermsWri
PendingTerm term = new PendingTerm(BytesRef.deepCopyOf(text), state);
pending.add(term);
numTerms++;
+ if (firstPendingTerm == null) {
+ firstPendingTerm = term;
+ }
+ lastPendingTerm = term;
}
}
@@ -853,7 +854,7 @@ public final class OrdsBlockTreeTermsWri
}
// Finishes all terms in this field
- public void finish(BytesRef minTerm, BytesRef maxTerm) throws IOException {
+ public void finish() throws IOException {
if (numTerms > 0) {
// if (DEBUG) System.out.println("BTTW.finish pending.size()=" + pending.size());
@@ -881,6 +882,12 @@ public final class OrdsBlockTreeTermsWri
// w.close();
// }
+ assert firstPendingTerm != null;
+ BytesRef minTerm = new BytesRef(firstPendingTerm.termBytes);
+
+ assert lastPendingTerm != null;
+ BytesRef maxTerm = new BytesRef(lastPendingTerm.termBytes);
+
fields.add(new FieldMetaData(fieldInfo,
((PendingBlock) pending.get(0)).index.getEmptyOutput(),
numTerms,
Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/codecs/blocktree/BlockTreeTermsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/codecs/blocktree/BlockTreeTermsWriter.java?rev=1613268&r1=1613267&r2=1613268&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/codecs/blocktree/BlockTreeTermsWriter.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/codecs/blocktree/BlockTreeTermsWriter.java Thu Jul 24 20:16:56 2014
@@ -373,21 +373,15 @@ public final class BlockTreeTermsWriter
TermsEnum termsEnum = terms.iterator(null);
TermsWriter termsWriter = new TermsWriter(fieldInfos.fieldInfo(field));
- BytesRef minTerm = null;
- BytesRef maxTerm = new BytesRef();
while (true) {
BytesRef term = termsEnum.next();
if (term == null) {
break;
}
- if (minTerm == null) {
- minTerm = BytesRef.deepCopyOf(term);
- }
- maxTerm.copyBytes(term);
termsWriter.write(term, termsEnum);
}
- termsWriter.finish(minTerm, minTerm == null ? null : maxTerm);
+ termsWriter.finish();
}
}
@@ -566,13 +560,16 @@ public final class BlockTreeTermsWriter
// Pending stack of terms and blocks. As terms arrive (in sorted order)
// we append to this stack, and once the top of the stack has enough
- // terms starting with a common prefix, write write a new block with
+ // terms starting with a common prefix, we write a new block with
// those terms and replace those terms in the stack with a new block:
private final List<PendingEntry> pending = new ArrayList<>();
// Reused in writeBlocks:
private final List<PendingBlock> newBlocks = new ArrayList<>();
+ private PendingTerm firstPendingTerm;
+ private PendingTerm lastPendingTerm;
+
/** Writes the top count entries in pending, using prevTerm to compute the prefix. */
void writeBlocks(int prefixLength, int count) throws IOException {
@@ -903,6 +900,10 @@ public final class BlockTreeTermsWriter
PendingTerm term = new PendingTerm(text, state);
pending.add(term);
numTerms++;
+ if (firstPendingTerm == null) {
+ firstPendingTerm = term;
+ }
+ lastPendingTerm = term;
}
}
@@ -944,7 +945,7 @@ public final class BlockTreeTermsWriter
}
// Finishes all terms in this field
- public void finish(BytesRef minTerm, BytesRef maxTerm) throws IOException {
+ public void finish() throws IOException {
if (numTerms > 0) {
// if (DEBUG) System.out.println("BTTW: finish prefixStarts=" + Arrays.toString(prefixStarts));
@@ -973,6 +974,11 @@ public final class BlockTreeTermsWriter
w.close();
}
*/
+ assert firstPendingTerm != null;
+ BytesRef minTerm = new BytesRef(firstPendingTerm.termBytes);
+
+ assert lastPendingTerm != null;
+ BytesRef maxTerm = new BytesRef(lastPendingTerm.termBytes);
fields.add(new FieldMetaData(fieldInfo,
((PendingBlock) pending.get(0)).index.getEmptyOutput(),
Modified: lucene/dev/trunk/lucene/sandbox/src/java/org/apache/lucene/codecs/idversion/VersionBlockTreeTermsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/sandbox/src/java/org/apache/lucene/codecs/idversion/VersionBlockTreeTermsWriter.java?rev=1613268&r1=1613267&r2=1613268&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/sandbox/src/java/org/apache/lucene/codecs/idversion/VersionBlockTreeTermsWriter.java (original)
+++ lucene/dev/trunk/lucene/sandbox/src/java/org/apache/lucene/codecs/idversion/VersionBlockTreeTermsWriter.java Thu Jul 24 20:16:56 2014
@@ -247,21 +247,15 @@ public final class VersionBlockTreeTerms
TermsEnum termsEnum = terms.iterator(null);
TermsWriter termsWriter = new TermsWriter(fieldInfos.fieldInfo(field));
- BytesRef minTerm = null;
- BytesRef maxTerm = new BytesRef();
while (true) {
BytesRef term = termsEnum.next();
if (term == null) {
break;
}
- if (minTerm == null) {
- minTerm = BytesRef.deepCopyOf(term);
- }
- maxTerm.copyBytes(term);
termsWriter.write(term, termsEnum);
}
- termsWriter.finish(minTerm, minTerm == null ? null : maxTerm);
+ termsWriter.finish();
}
}
@@ -442,13 +436,16 @@ public final class VersionBlockTreeTerms
// Pending stack of terms and blocks. As terms arrive (in sorted order)
// we append to this stack, and once the top of the stack has enough
- // terms starting with a common prefix, write write a new block with
+ // terms starting with a common prefix, we write a new block with
// those terms and replace those terms in the stack with a new block:
private final List<PendingEntry> pending = new ArrayList<>();
// Reused in writeBlocks:
private final List<PendingBlock> newBlocks = new ArrayList<>();
+ private PendingTerm firstPendingTerm;
+ private PendingTerm lastPendingTerm;
+
/** Writes the top count entries in pending, using prevTerm to compute the prefix. */
void writeBlocks(int prefixLength, int count) throws IOException {
@@ -756,6 +753,10 @@ public final class VersionBlockTreeTerms
PendingTerm term = new PendingTerm(BytesRef.deepCopyOf(text), state);
pending.add(term);
numTerms++;
+ if (firstPendingTerm == null) {
+ firstPendingTerm = term;
+ }
+ lastPendingTerm = term;
}
}
@@ -797,7 +798,7 @@ public final class VersionBlockTreeTerms
}
// Finishes all terms in this field
- public void finish(BytesRef minTerm, BytesRef maxTerm) throws IOException {
+ public void finish() throws IOException {
if (numTerms > 0) {
// TODO: if pending.size() is already 1 with a non-zero prefix length
@@ -824,6 +825,12 @@ public final class VersionBlockTreeTerms
// w.close();
// }
+ assert firstPendingTerm != null;
+ BytesRef minTerm = new BytesRef(firstPendingTerm.termBytes);
+
+ assert lastPendingTerm != null;
+ BytesRef maxTerm = new BytesRef(lastPendingTerm.termBytes);
+
fields.add(new FieldMetaData(fieldInfo,
((PendingBlock) pending.get(0)).index.getEmptyOutput(),
numTerms,