mikemccand commented on code in PR #13149: URL: https://github.com/apache/lucene/pull/13149#discussion_r1514835629
########## lucene/core/src/java/org/apache/lucene/util/bkd/DocIdsWriter.java: ########## @@ -36,6 +36,66 @@ final class DocIdsWriter { private final int[] scratch; + private final ScratchDocIdSetIterator scratchDocIdSetIterator = new ScratchDocIdSetIterator(); + + /** + * DocIdSetIterator to be used to iterate over the scratch buffer. A single instance is reused to + * avoid re-allocating the object. The reset method should be called before each use with the + * count. + * + * <p>The main reason for existing is to be able to call the {@link + * IntersectVisitor#visit(DocIdSetIterator)} method rather than the {@link + * IntersectVisitor#visit(int)} method. This seems to make a difference in performance, probably + * due to fewer virtual calls then happening (once per read call rather than once per doc). + */ + private class ScratchDocIdSetIterator extends DocIdSetIterator { + + private int index = -1; + private int count = -1; + + @Override + public int docID() { + if (index < 0) { + return -1; + } + if (index >= count) { + return NO_MORE_DOCS; + } + return scratch[index]; + } + + @Override + public int nextDoc() throws IOException { + index++; + if (index >= count) { + return NO_MORE_DOCS; + } + return scratch[index]; + } + + @Override + public int advance(int target) throws IOException { + while (index < count && scratch[index] < target) { Review Comment: Do we even need to implement this method? Can we throw `UOE` instead? It's a bit scary that it's O(N), though, in practice, `scratch` is a smallish buffer? -- 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