From 467f163b2df1904c31f7b6bd7b37836e68b2ca42 Mon Sep 17 00:00:00 2001 From: Will Leonard Date: Fri, 12 Oct 2018 16:14:05 -0400 Subject: [PATCH] Reduce array allocations in utils each_element --- lib/roo/utils.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/roo/utils.rb b/lib/roo/utils.rb index 484d9190..dcaedde5 100644 --- a/lib/roo/utils.rb +++ b/lib/roo/utils.rb @@ -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