You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2014/10/16 16:01:53 UTC
svn commit: r1632314 - in
/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util:
FixedBitSet.java NotDocIdSet.java RoaringDocIdSet.java SparseFixedBitSet.java
Author: jpountz
Date: Thu Oct 16 14:01:53 2014
New Revision: 1632314
URL: http://svn.apache.org/r1632314
Log:
LUCENE-6009: Remove redundant == NO_MORE_DOCS checks.
Modified:
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/NotDocIdSet.java
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/RoaringDocIdSet.java
lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/SparseFixedBitSet.java
Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java?rev=1632314&r1=1632313&r2=1632314&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java Thu Oct 16 14:01:53 2014
@@ -59,24 +59,7 @@ public final class FixedBitSet extends D
@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 D
@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;
Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/NotDocIdSet.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/NotDocIdSet.java?rev=1632314&r1=1632313&r2=1632314&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/NotDocIdSet.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/NotDocIdSet.java Thu Oct 16 14:01:53 2014
@@ -82,9 +82,6 @@ public final class NotDocIdSet extends D
@Override
public int nextDoc() throws IOException {
- if (doc == NO_MORE_DOCS) {
- return NO_MORE_DOCS;
- }
return advance(doc + 1);
}
Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/RoaringDocIdSet.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/RoaringDocIdSet.java?rev=1632314&r1=1632313&r2=1632314&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/RoaringDocIdSet.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/RoaringDocIdSet.java Thu Oct 16 14:01:53 2014
@@ -282,9 +282,6 @@ public class RoaringDocIdSet extends Doc
@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();
Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/SparseFixedBitSet.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/SparseFixedBitSet.java?rev=1632314&r1=1632313&r2=1632314&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/SparseFixedBitSet.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/util/SparseFixedBitSet.java Thu Oct 16 14:01:53 2014
@@ -248,16 +248,17 @@ public class SparseFixedBitSet extends D
@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 D
} 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 D
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);
@@ -313,17 +314,6 @@ public class SparseFixedBitSet extends D
}
@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
// we cache it to avoid performance traps eg. when sorting iterators by