jpountz commented on code in PR #11928:
URL: https://github.com/apache/lucene/pull/11928#discussion_r1023716348


##########
lucene/core/src/java/org/apache/lucene/search/DisjunctionDISIApproximation.java:
##########
@@ -45,29 +51,54 @@ public long cost() {
 
   @Override
   public int docID() {
-    return subIterators.top().doc;
+    return docID;
   }
 
-  @Override
-  public int nextDoc() throws IOException {
+  private int doNext(int target) throws IOException {
+    if (target == DocIdSetIterator.NO_MORE_DOCS) {
+      docID = DocIdSetIterator.NO_MORE_DOCS;
+      return docID;
+    }
+
     DisiWrapper top = subIterators.top();
-    final int doc = top.doc;
     do {
-      top.doc = top.approximation.nextDoc();
+      top.doc = top.approximation.advance(target);
+      if (top.doc == target) {
+        subIterators.updateTop();
+        docID = target;
+        return docID;
+      }
       top = subIterators.updateTop();
-    } while (top.doc == doc);
+    } while (top.doc < target);
+    docID = top.doc;
 
-    return top.doc;
+    return docID;
+  }
+
+  @Override
+  public int nextDoc() throws IOException {
+    if (docID == DocIdSetIterator.NO_MORE_DOCS) {
+      return docID;
+    }

Review Comment:
   This is not necessary, it's illegal to call `nextDoc` on an exhausted 
`DocIdSetIterator`.



##########
lucene/core/src/java/org/apache/lucene/search/DisjunctionDISIApproximation.java:
##########
@@ -45,29 +51,54 @@ public long cost() {
 
   @Override
   public int docID() {
-    return subIterators.top().doc;
+    return docID;
   }
 
-  @Override
-  public int nextDoc() throws IOException {
+  private int doNext(int target) throws IOException {
+    if (target == DocIdSetIterator.NO_MORE_DOCS) {
+      docID = DocIdSetIterator.NO_MORE_DOCS;
+      return docID;
+    }

Review Comment:
   In general I'm dubious about such checks for `NO_MORE_DOCS` since we need to 
do this check on every candidate match but this condition is true at most once 
per segment, and often never. So it looks like extra overhead that doesn't 
bring significant value, and could prevent e.g. inlining due to increased 
bytecode size.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to