Skip to content

Commit

Permalink
feat: CSS queries use builtins if they are more performant
Browse files Browse the repository at this point in the history
Notably, on libxml2 CSS class queries are now ~2x faster using the
`nokogiri-builtin:css-class` function.

Closes #2135
  • Loading branch information
flavorjones committed Dec 18, 2020
1 parent 9f5bb99 commit 5d0b7fe
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/nokogiri/xml/searchable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,10 @@ def css_rules_to_xpath(rules, ns)
end

def xpath_query_from_css_rule(rule, ns)
visitor = Nokogiri::CSS::XPathVisitorOptimallyUseBuiltins.new
self.class::IMPLIED_XPATH_CONTEXTS.map do |implied_xpath_context|
CSS.xpath_for(rule.to_s, :prefix => implied_xpath_context, :ns => ns)
CSS.xpath_for(rule.to_s, {:prefix => implied_xpath_context, :ns => ns,
:visitor => visitor})
end.join(" | ")
end

Expand Down

0 comments on commit 5d0b7fe

Please sign in to comment.