XPath optimize preparation for positional predicates that uses last()#339
Open
tompng wants to merge 1 commit into
Open
XPath optimize preparation for positional predicates that uses last()#339tompng wants to merge 1 commit into
last()#339tompng wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR expands the internal representation of “simple positional predicates” in the XPath parser to support last()-based forms (e.g., [last()], [last()-N], and comparisons against last()-N), enabling future axis-scan optimizations while preserving correct XPath behavior.
Changes:
- Extends
position_operationto recognizelast()/last()-INTEGERand to normalize positional predicates into 0-based:index_*and:reverse_index_*selector forms. - Updates sibling-axis scanning and the generic slow-path selector application to operate on the new selector operators/0-based indexing.
- Adds test coverage for inverted
position()comparisons andlast()-based predicates on preceding-/following-sibling axes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
lib/rexml/xpath_parser.rb |
Adds last()-aware predicate detection and migrates selector operators to 0-based :index_* / :reverse_index_*, updating scan/slow-path handling accordingly. |
test/xpath/test_axis_preceding_sibling.rb |
Adds assertions covering last()/last()-N and inverted position() comparisons for sibling axes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Expand optimizable simple positional queries to support `[last()]` `[last()-N]` and `[position() <=> last()-N]`. This will open the door for future optimization
3a226e6 to
e789f1c
Compare
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.
Expand optimizable simple positional queries to support
[last()][last()-N]and[position() <=> last()-N].This will open the door for future optimization.
Simple positional predicates that may be optimized are represented as:
Example
Example optimization of preceding-sibling/following-sibling (not included in this PR)