Skip to content

Commit 020085a

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 020085a

6 files changed

Lines changed: 484 additions & 244 deletions

File tree

lib/rexml/parsers/xpathparser.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,10 @@ 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+
type = n[0]
661+
parsed.push(:self, :node) if type == :document || type == :child || type == :union
658662
end
659663
path
660664
end

0 commit comments

Comments
 (0)