Skip to content

Simplify SortedDocIDMerger.next()#16073

Open
Tim-Brooks wants to merge 4 commits into
apache:mainfrom
Tim-Brooks:doc_id_merge_clean-ups
Open

Simplify SortedDocIDMerger.next()#16073
Tim-Brooks wants to merge 4 commits into
apache:mainfrom
Tim-Brooks:doc_id_merge_clean-ups

Conversation

@Tim-Brooks
Copy link
Copy Markdown
Contributor

The else if (queue.size() > 0) guard is always true when reached:
an empty queue sets queueMinDocID to NO_MORE_DOCS, so any valid nextDoc
satisfies nextDoc < queueMinDocID and takes the fast path first. Replace
with else and add a comment explaining why the queue is never empty
at that point.

- Drop the `else if (queue.size() > 0)` guard in next(): the queue is
guaranteed non-empty when that branch is reached, since an empty queue
sets queueMinDocID to NO_MORE_DOCS and any valid nextDoc would have
taken the fast path. Add a comment explaining the invariant.

- Simplify reset() by handling the first sub before the loop, removing
the `boolean first` flag and the dead `current = null` assignment.
@github-actions github-actions Bot added this to the 10.5.0 milestone May 15, 2026
Copy link
Copy Markdown
Contributor

@martijnvg martijnvg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants