Apache Solr open-source search software
LUCENE-6009: Remove redundant == NO_MORE_DOCS checks.
Adrien Grand6697abbb285e
diff --git a/lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java b/lucene/core/src/java/org/apache/lucene/util/FixedBitSet.javaindex ba645a50140..e155a70d954 100644--- a/lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java+++ b/lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java@@ -59,24 +59,7 @@ public final class FixedBitSet extends DocIdSet implements MutableBits {@Overridepublic int nextDoc() {- if (doc == NO_MORE_DOCS || ++doc >= numBits) {- return doc = NO_MORE_DOCS;- }- int i = doc >> 6;- long word = bits[i] >> doc; // skip all the bits to the right of index-- if (word != 0) {- return doc = doc + Long.numberOfTrailingZeros(word);- }-- while (++i < numWords) {- word = bits[i];- if (word != 0) {- return doc = (i << 6) + Long.numberOfTrailingZeros(word);- }- }-- return doc = NO_MORE_DOCS;+ return advance(doc + 1);}@Override@@ -91,7 +74,7 @@ public final class FixedBitSet extends DocIdSet implements MutableBits {@Overridepublic int advance(int target) {- if (doc == NO_MORE_DOCS || target >= numBits) {+ if (target >= numBits) {return doc = NO_MORE_DOCS;}int i = target >> 6;diff --git a/lucene/core/src/java/org/apache/lucene/util/NotDocIdSet.java b/lucene/core/src/java/org/apache/lucene/util/NotDocIdSet.javaindex 44f883877d6..6261de92fce 100644--- a/lucene/core/src/java/org/apache/lucene/util/NotDocIdSet.java+++ b/lucene/core/src/java/org/apache/lucene/util/NotDocIdSet.java@@ -82,9 +82,6 @@ public final class NotDocIdSet extends DocIdSet {@Overridepublic int nextDoc() throws IOException {- if (doc == NO_MORE_DOCS) {- return NO_MORE_DOCS;- }return advance(doc + 1);}diff --git a/lucene/core/src/java/org/apache/lucene/util/RoaringDocIdSet.java b/lucene/core/src/java/org/apache/lucene/util/RoaringDocIdSet.javaindex 5f6844add26..93d4ab85bfa 100644--- a/lucene/core/src/java/org/apache/lucene/util/RoaringDocIdSet.java+++ b/lucene/core/src/java/org/apache/lucene/util/RoaringDocIdSet.java@@ -282,9 +282,6 @@ public class RoaringDocIdSet extends DocIdSet {@Overridepublic int nextDoc() throws IOException {- if (doc == NO_MORE_DOCS) {- return NO_MORE_DOCS;- }final int subNext = sub.nextDoc();if (subNext == NO_MORE_DOCS) {return firstDocFromNextBlock();diff --git a/lucene/core/src/java/org/apache/lucene/util/SparseFixedBitSet.java b/lucene/core/src/java/org/apache/lucene/util/SparseFixedBitSet.javaindex 23448208033..7a971956342 100644--- a/lucene/core/src/java/org/apache/lucene/util/SparseFixedBitSet.java+++ b/lucene/core/src/java/org/apache/lucene/util/SparseFixedBitSet.java@@ -248,16 +248,17 @@ public class SparseFixedBitSet extends DocIdSet implements Bits {@Overridepublic int nextDoc() throws IOException {- if (++doc >= length) {- return doc = NO_MORE_DOCS;- }- return currentOrNextDoc();+ return advance(doc + 1);}- private int currentOrNextDoc() {- final int i4096 = doc >>> 12;+ @Override+ public int advance(int target) throws IOException {+ final int i4096 = target >>> 12;+ if (i4096 >= indices.length) {+ return doc = NO_MORE_DOCS;+ }final long index = indices[i4096];- int i64 = doc >>> 6;+ int i64 = target >>> 6;long indexBits = index >>> i64;if (indexBits == 0) {// if the index is zero, it means that there is no value in the@@ -270,7 +271,7 @@ public class SparseFixedBitSet extends DocIdSet implements Bits {} else {// We know we still have some 64-bits blocks that have bits set, let's// advance to the next one by skipping trailing zeros of the index- int i1 = doc & 0x3F;+ int i1 = target & 0x3F;int trailingZeros = Long.numberOfTrailingZeros(indexBits);if (trailingZeros != 0) {// no bits in the current long, go to the next one@@ -285,7 +286,7 @@ public class SparseFixedBitSet extends DocIdSet implements Bits {int longIndex = Long.bitCount(index & ((1L << i64) - 1)); // shifts are mod 64 in javafinal long[] longArray = bits[i4096];assert longArray[longIndex] != 0;- long bits = SparseFixedBitSet.this.bits[i4096][longIndex] >>> i1; // shifts are mod 64 in java+ long bits = longArray[longIndex] >>> i1; // shifts are mod 64 in javaif (bits != 0L) {// hurray, we found some non-zero bits, this gives us the next document:i1 += Long.numberOfTrailingZeros(bits);@@ -312,17 +313,6 @@ public class SparseFixedBitSet extends DocIdSet implements Bits {}}- @Override- public int advance(int target) throws IOException {- if (target >= length) {- return doc = NO_MORE_DOCS;- } else {- doc = target;- }-- return currentOrNextDoc();- }-@Overridepublic long cost() {// although constant-time, approximateCardinality is a bit expensive so