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 23:11:03 UTC

svn commit: r1613303 - in /lucene/dev/branches/branch_4x: ./ lucene/codecs/src/java/org/apache/lucene/codecs/blocktreeords/ lucene/core/src/java/org/apache/lucene/codecs/blocktree/ lucene/sandbox/src/java/org/apache/lucene/codecs/idversion/

Author: mikemccand
Date: Thu Jul 24 21:11:03 2014
New Revision: 1613303

URL: http://svn.apache.org/r1613303
Log:
LUCENE-5610: optimization: just use already allocated/copied PendingTerm to for min/maxTerm

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blocktreeords/OrdsBlockTreeTermsWriter.java
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/blocktree/BlockTreeTermsWriter.java
    lucene/dev/branches/branch_4x/lucene/sandbox/src/java/org/apache/lucene/codecs/idversion/VersionBlockTreeTermsWriter.java

Modified: lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blocktreeords/OrdsBlockTreeTermsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blocktreeords/OrdsBlockTreeTermsWriter.java?rev=1613303&r1=1613302&r2=1613303&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blocktreeords/OrdsBlockTreeTermsWriter.java (original)
+++ lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blocktreeords/OrdsBlockTreeTermsWriter.java Thu Jul 24 21:11:03 2014
@@ -443,15 +443,15 @@ 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 BytesRef minTerm;
-    private BytesRef maxTerm = new BytesRef();
+    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 {
@@ -808,10 +808,10 @@ public final class OrdsBlockTreeTermsWri
       pending.add(term);
       numTerms++;
 
-      if (minTerm == null) {
-        minTerm = BytesRef.deepCopyOf(text);
+      if (firstPendingTerm == null) {
+        firstPendingTerm = term;
       }
-      maxTerm.copyBytes(text);
+      lastPendingTerm = term;
     }
 
     /** Pushes the new term to the top of the stack, and writes new blocks. */
@@ -884,6 +884,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/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/blocktree/BlockTreeTermsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/blocktree/BlockTreeTermsWriter.java?rev=1613303&r1=1613302&r2=1613303&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/blocktree/BlockTreeTermsWriter.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/blocktree/BlockTreeTermsWriter.java Thu Jul 24 21:11:03 2014
@@ -547,15 +547,15 @@ 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 BytesRef minTerm;
-    private BytesRef maxTerm = new BytesRef();
+    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 {
@@ -905,9 +905,6 @@ public final class BlockTreeTermsWriter 
       state.totalTermFreq = stats.totalTermFreq;
       postingsWriter.finishTerm(state);
 
-      if (minTerm == null) {
-        minTerm = BytesRef.deepCopyOf(text);
-      }
       sumDocFreq += state.docFreq;
       sumTotalTermFreq += state.totalTermFreq;
       pushTerm(text);
@@ -915,7 +912,10 @@ public final class BlockTreeTermsWriter 
       PendingTerm term = new PendingTerm(text, state);
       pending.add(term);
       numTerms++;
-      maxTerm.copyBytes(text);
+      if (firstPendingTerm == null) {
+        firstPendingTerm = term;
+      }
+      lastPendingTerm = term;
     }
 
     /** Pushes the new term to the top of the stack, and writes new blocks. */
@@ -989,6 +989,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/branches/branch_4x/lucene/sandbox/src/java/org/apache/lucene/codecs/idversion/VersionBlockTreeTermsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/sandbox/src/java/org/apache/lucene/codecs/idversion/VersionBlockTreeTermsWriter.java?rev=1613303&r1=1613302&r2=1613303&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/sandbox/src/java/org/apache/lucene/codecs/idversion/VersionBlockTreeTermsWriter.java (original)
+++ lucene/dev/branches/branch_4x/lucene/sandbox/src/java/org/apache/lucene/codecs/idversion/VersionBlockTreeTermsWriter.java Thu Jul 24 21:11:03 2014
@@ -423,15 +423,15 @@ 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 BytesRef minTerm;
-    private BytesRef maxTerm = new BytesRef();
+    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 {
@@ -761,11 +761,10 @@ public final class VersionBlockTreeTerms
         PendingTerm term = new PendingTerm(BytesRef.deepCopyOf(text), state);
         pending.add(term);
         numTerms++;
-
-        if (minTerm == null) {
-          minTerm = BytesRef.deepCopyOf(text);
+        if (firstPendingTerm == null) {
+          firstPendingTerm = term;
         }
-        maxTerm.copyBytes(text);
+        lastPendingTerm = term;
       }
     }
 
@@ -835,6 +834,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,