Optimize descendant-or-self and child axes.

By using NodeSet#concat we can further reduce the amount of object allocations.
This in turn greatly reduces the time it takes to query large documents using
descendant-or-self.
This commit is contained in:
Yorick Peterse 2014-09-05 20:20:13 +02:00
parent 9f6035e784
commit ef03a12f99
1 changed files with 6 additions and 3 deletions

View File

@ -338,8 +338,11 @@ module Oga
# @return [Oga::XML::NodeSet] # @return [Oga::XML::NodeSet]
# #
def on_axis_descendant_or_self(ast_node, context) def on_axis_descendant_or_self(ast_node, context)
return on_test(ast_node, context) + nodes = on_test(ast_node, context)
on_axis_descendant(ast_node, context)
nodes.concat(on_axis_descendant(ast_node, context))
return nodes
end end
## ##
@ -1585,7 +1588,7 @@ module Oga
children = XML::NodeSet.new children = XML::NodeSet.new
nodes.each do |xml_node| nodes.each do |xml_node|
children += xml_node.children children.concat(xml_node.children)
end end
return children return children