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 2010/09/04 11:49:18 UTC

svn commit: r992571 - /lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/FieldComparator.java

Author: mikemccand
Date: Sat Sep  4 09:49:18 2010
New Revision: 992571

URL: http://svn.apache.org/viewvc?rev=992571&view=rev
Log:
LUCENE-2631: fix small perf issues with String/TermOrdValComparator

Modified:
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/FieldComparator.java

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/FieldComparator.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/FieldComparator.java?rev=992571&r1=992570&r2=992571&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/FieldComparator.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/FieldComparator.java Sat Sep  4 09:49:18 2010
@@ -731,10 +731,7 @@ public abstract class FieldComparator {
     @Override
     public int compare(int slot1, int slot2) {
       if (readerGen[slot1] == readerGen[slot2]) {
-        int cmp = ords[slot1] - ords[slot2];
-        if (cmp != 0) {
-          return cmp;
-        }
+        return ords[slot1] - ords[slot2];
       }
 
       final BytesRef val1 = values[slot1];
@@ -786,6 +783,7 @@ public abstract class FieldComparator {
     public void copy(int slot, int doc) {
       final int ord = (int) currentDocToOrd.get(doc);
       if (ord == 0) {
+        ords[slot] = 0;
         values[slot] = null;
       } else {
         ords[slot] = ord;
@@ -813,22 +811,31 @@ public abstract class FieldComparator {
       bottomSlot = bottom;
 
       bottomValue = values[bottomSlot];
-      if (bottomValue == null) {
-        // 0 ord is null for all segments
-        assert ords[bottomSlot] == 0;
-        bottomOrd = 0;
+      if (currentReaderGen == readerGen[bottomSlot]) {
+        bottomOrd = ords[bottomSlot];
         bottomSameReader = true;
       } else {
-        final int index = binarySearch(tempBR, termsIndex, bottomValue);
-        if (index < 0) {
-          bottomOrd = -index - 2;
-          bottomSameReader = false;
-        } else {
-          bottomOrd = index;
-          // exact value match
+        if (bottomValue == null) {
+          // 0 ord is null for all segments
+          assert ords[bottomSlot] == 0;
+          bottomOrd = 0;
           bottomSameReader = true;
+          readerGen[bottomSlot] = currentReaderGen;
+        } else {
+          final int index = binarySearch(tempBR, termsIndex, bottomValue);
+          if (index < 0) {
+            bottomOrd = -index - 2;
+            bottomSameReader = false;
+          } else {
+            bottomOrd = index;
+            // exact value match
+            bottomSameReader = true;
+          }
         }
       }
+      if (bottomSameReader) {
+        readerGen[bottomSlot] = currentReaderGen;
+      }
     }
 
     @Override