From ef03a12f99e138b6b44144bdeb50ac1107602fa6 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Fri, 5 Sep 2014 20:20:13 +0200 Subject: [PATCH] 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. --- lib/oga/xpath/evaluator.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/oga/xpath/evaluator.rb b/lib/oga/xpath/evaluator.rb index ece484d..15aed07 100644 --- a/lib/oga/xpath/evaluator.rb +++ b/lib/oga/xpath/evaluator.rb @@ -338,8 +338,11 @@ module Oga # @return [Oga::XML::NodeSet] # def on_axis_descendant_or_self(ast_node, context) - return on_test(ast_node, context) + - on_axis_descendant(ast_node, context) + nodes = on_test(ast_node, context) + + nodes.concat(on_axis_descendant(ast_node, context)) + + return nodes end ## @@ -1585,7 +1588,7 @@ module Oga children = XML::NodeSet.new nodes.each do |xml_node| - children += xml_node.children + children.concat(xml_node.children) end return children