Repository navigation
🐛 fix(xpath): keep [N] with later predicates linear - #2446
Merged
gaborbernat merged 1 commit intoNov 17, 2026
Merged
Conversation
A positional predicate that was not the last predicate of its step fell back to walking the whole axis for each context node. A predicate such as ancestor::b[1][@x] now takes the nearest node from the walk memo or the positional index, and the predicates after it judge that one node. Fixes tox-dev#2444
gaborbernat
enabled auto-merge (squash)
November 17, 2026 14:49
Merging this PR will not alter performance
Comparing Footnotes
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An XPath step whose positional predicate is not its last predicate, such as
ancestor::b[1][@x], walked its whole axis again for every context node. On a long document the total work grew with the square of the document size, even when the selected node sat next to the context.The first positional predicate now selects the node, and the predicates after it judge only that node, where
position()andlast()are 1 as they would be for the step's own single selection. The walk memo and the positional index answer these forms, soaxis::name[N][predicate]costs the same asaxis::name[predicate][N]. The plain walk stays for forms that do not select by position.The new
work_stepstests cover each axis (ancestor,ancestor-or-self,preceding,following,preceding-sibling,following-sibling,descendant) with[1],[2]and[last()]followed by a predicate, and check that the linear tests fail before the change. The correctness tests compare each form with the same selection written through aposition() > 0barrier, which keeps the plain walk, and they also run the form inside an outer predicate.Fixes #2444