Skip to content

Apache Lucene open-source search software

LUCENE-3892: inline nextDoc() for DocsAndPositionsEnum.advance

Michael McCandless7bf0d1f80445
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/block/BlockPostingsReader.java b/lucene/core/src/java/org/apache/lucene/codecs/block/BlockPostingsReader.java
index d3414b5a008..bf65f91f08d 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/block/BlockPostingsReader.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/block/BlockPostingsReader.java
@@ -833,23 +833,43 @@ public final class BlockPostingsReader extends PostingsReaderBase {
}
}
- // nocommit inline nextDoc here
+ // Now scan... this is an inlined/pared down version
+ // of nextDoc():
+ while (true) {
+ if (DEBUG) {
+ System.out.println(" scan doc=" + accum + " docBufferUpto=" + docBufferUpto);
+ }
+ if (docUpto == docFreq) {
+ return doc = NO_MORE_DOCS;
+ }
+ if (docBufferUpto == blockSize) {
+ // nocommit hmm skip freq? but: we don't ever
+ // scan over more than one block?
+ refillDocs();
+ }
+ accum += docDeltaBuffer[docBufferUpto];
+ freq = freqBuffer[docBufferUpto];
+ posPendingCount += freq;
+ docBufferUpto++;
+ docUpto++;
- // Now scan:
- while (nextDoc() != NO_MORE_DOCS) {
- if (doc >= target) {
- if (DEBUG) {
- System.out.println(" advance return doc=" + doc);
- }
- return doc;
+ if (accum >= target) {
+ break;
}
}
- if (DEBUG) {
- System.out.println(" advance return doc=END");
+ if (liveDocs == null || liveDocs.get(accum)) {
+ if (DEBUG) {
+ System.out.println(" return doc=" + accum);
+ }
+ position = 0;
+ return doc = accum;
+ } else {
+ if (DEBUG) {
+ System.out.println(" now do nextDoc()");
+ }
+ return nextDoc();
}
-
- return NO_MORE_DOCS;
}
// nocommit in theory we could avoid loading frq block