From 739e3b474cb562f774a0e80f5f33b3b18ec7d8c5 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Sun, 12 Apr 2015 22:45:42 +0200 Subject: [PATCH] Optimize Traversal#each_node allocations This removes the need for allocating an Array for every set of child nodes. --- lib/oga/xml/traversal.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/oga/xml/traversal.rb b/lib/oga/xml/traversal.rb index 4903e07..9e7dc5d 100644 --- a/lib/oga/xml/traversal.rb +++ b/lib/oga/xml/traversal.rb @@ -39,7 +39,9 @@ module Oga catch :skip_children do yield current - visit = current.children.to_a + visit + current.children.to_a.reverse_each do |child| + visit.unshift(child) + end end end end