Skip to content

Commit

Permalink
Merge pull request #466 from will89/improve-utils-each_element
Browse files Browse the repository at this point in the history
Reduce array allocations in Roo::Utils.each_element
  • Loading branch information
chopraanmol1 authored Oct 14, 2018
2 parents 5fc4378 + 467f163 commit 01d1a1c
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 01d1a1c

Please sign in to comment.