From 9f6035e7849048f6d0ef23677ebb7f7079e77ddc Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Fri, 5 Sep 2014 19:58:37 +0200 Subject: [PATCH] Reduce object allocations in on_axis_descendant By using Traversal#each_node and _not_ calling on_test() (which was only called for node_matches?) we can save ourselves a few object allocations. --- lib/oga/xpath/evaluator.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/oga/xpath/evaluator.rb b/lib/oga/xpath/evaluator.rb index 4187fae..ece484d 100644 --- a/lib/oga/xpath/evaluator.rb +++ b/lib/oga/xpath/evaluator.rb @@ -318,8 +318,13 @@ module Oga nodes = XML::NodeSet.new context.each do |context_node| - nodes.concat(on_test(ast_node, context_node.children)) - nodes.concat(on_axis_descendant(ast_node, context_node.children)) + context_node.children.each do |node| + nodes << node if node_matches?(node, ast_node) + end + + context_node.each_node do |node| + nodes << node if node_matches?(node, ast_node) + end end return nodes