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.
This commit is contained in:
Yorick Peterse 2015-08-07 14:08:54 +02:00
parent 32b75bf62c
commit 9b98e75115
1 changed files with 3 additions and 3 deletions

View File

@ -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