Skip to content

Commit

Permalink
Reduce array allocations in utils each_element
Browse files Browse the repository at this point in the history
  • Loading branch information
will89 committed Oct 12, 2018
1 parent 5fc4378 commit 467f163
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/roo/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ def load_xml(path)

# Yield each element of a given type ('row', 'c', etc.) to caller
def each_element(path, elements)
elements = Array(elements)
Nokogiri::XML::Reader(::File.open(path, 'rb'), nil, nil, Nokogiri::XML::ParseOptions::NOBLANKS).each do |node|
next unless node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT && Array(elements).include?(node.name)
next unless node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT && elements.include?(node.name)
yield Nokogiri::XML(node.outer_xml).root if block_given?
end
end
Expand Down

0 comments on commit 467f163

Please sign in to comment.