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:
parent
32b75bf62c
commit
9b98e75115
|
@ -31,16 +31,16 @@ module Oga
|
||||||
# @yieldparam [Oga::XML::Node] The current node.
|
# @yieldparam [Oga::XML::Node] The current node.
|
||||||
#
|
#
|
||||||
def each_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?
|
until visit.empty?
|
||||||
current = visit.shift
|
current = visit.pop
|
||||||
|
|
||||||
catch :skip_children do
|
catch :skip_children do
|
||||||
yield current
|
yield current
|
||||||
|
|
||||||
current.children.to_a.reverse_each do |child|
|
current.children.to_a.reverse_each do |child|
|
||||||
visit.unshift(child)
|
visit << child
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue