From 6697abbb285e9edb5012c2d161ce0546ad9dbae0 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Thu, 16 Oct 2014 14:01:53 +0000 Subject: [PATCH] LUCENE-6009: Remove redundant == NO_MORE_DOCS checks. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1632314 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/util/FixedBitSet.java | 21 ++----------- .../org/apache/lucene/util/NotDocIdSet.java | 3 -- .../apache/lucene/util/RoaringDocIdSet.java | 3 -- .../apache/lucene/util/SparseFixedBitSet.java | 30 +++++++------------ 4 files changed, 12 insertions(+), 45 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java b/lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java index 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 { @Override public 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 { @Override public 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.java index 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 { @Override public 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.java index 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 { @Override public 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.java index 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 { @Override public 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 java final 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 java if (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(); - } - @Override public long cost() { // although constant-time, approximateCardinality is a bit expensive so