Skip to content

Commit 15a8f52

Browse files
committed
Optimize XPath step
If a predicate of xpath is position-independent, we don't need to create nodesets that has many duplicated nodes with different positions.
1 parent 7ac7ef4 commit 15a8f52

6 files changed

Lines changed: 483 additions & 244 deletions

File tree

lib/rexml/parsers/xpathparser.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,9 @@ def PrimaryExpr path, parsed
655655
n = []
656656
OrExpr( contents, n )
657657
parsed.concat(n)
658+
# For xpath like `(/path[predicate1][predicate2])[predicate3][predicate4]`,
659+
# add a separator mark to distinguish predicates of the inner parentheses and the outer parentheses.
660+
parsed.push(:self, :node) if n[0] == :document || n[0] == :child
658661
end
659662
path
660663
end

0 commit comments

Comments
 (0)