From 67aefd7705df82e43a8670102400a5abab49f6e8 Mon Sep 17 00:00:00 2001 From: Paul Kmiec Date: Fri, 5 May 2023 08:58:17 -0700 Subject: Pipe output directly to str and avoid additional memory allocations Currently, there are lots of examples of code like this, ``` str << ('') ``` which create the string for the tag in memory before piping to str. We can avoid creating all of these intermediate strings by dropping the paranthesis and piping directly to str. This relies on the `str` passed around to handle lots of small appends. This is a problem when using RubyZip, but that is solved in the next commit. --- lib/axlsx/drawing/axes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/axlsx/drawing/axes.rb') diff --git a/lib/axlsx/drawing/axes.rb b/lib/axlsx/drawing/axes.rb index 0baad85f..eb4728c6 100644 --- a/lib/axlsx/drawing/axes.rb +++ b/lib/axlsx/drawing/axes.rb @@ -33,7 +33,7 @@ module Axlsx if options[:ids] # CatAxis must come first in the XML (for Microsoft Excel at least) sorted = axes.sort_by { |name, axis| axis.kind_of?(CatAxis) ? 0 : 1 } - sorted.each { |axis| str << (+'') } + sorted.each { |axis| str << '' } else axes.each { |axis| axis[1].to_xml_string(str) } end -- cgit v1.2.3