Apache Lucene open-source search software
LUCENE-2631: fix small perf issues with String/TermOrdValComparator
Michael McCandless6ee1ac44ee1c
diff --git a/lucene/src/java/org/apache/lucene/search/FieldComparator.java b/lucene/src/java/org/apache/lucene/search/FieldComparator.javaindex 9b140fff64b..e57c7005182 100644--- a/lucene/src/java/org/apache/lucene/search/FieldComparator.java+++ b/lucene/src/java/org/apache/lucene/search/FieldComparator.java@@ -731,10 +731,7 @@ public abstract class FieldComparator {@Overridepublic 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