From 9b98e75115de0d93ba64b18f2ec98181c5b6b11c Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Fri, 7 Aug 2015 14:08:54 +0200 Subject: [PATCH] Use pop/push vs shift/unshift in each_node While the performance difference between the old and new approach is pretty much negligible, it's simply not needed to use #shift/#unshift here. Thanks to Mon_Ouie from the #ruby IRC channel for suggesting this. --- lib/oga/xml/traversal.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/oga/xml/traversal.rb b/lib/oga/xml/traversal.rb index 9e7dc5d..b8f0707 100644 --- a/lib/oga/xml/traversal.rb +++ b/lib/oga/xml/traversal.rb @@ -31,16 +31,16 @@ module Oga # @yieldparam [Oga::XML::Node] The current node. # def each_node - visit = children.to_a.dup # copy it since we're modifying the array + visit = children.to_a.reverse until visit.empty? - current = visit.shift + current = visit.pop catch :skip_children do yield current current.children.to_a.reverse_each do |child| - visit.unshift(child) + visit << child end end end