summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/drawing/bar_series.rb
diff options
context:
space:
mode:
authorPaul Kmiec <[email protected]>2023-05-05 08:58:17 -0700
committerPaul Kmiec <[email protected]>2023-05-05 09:29:58 -0700
commit67aefd7705df82e43a8670102400a5abab49f6e8 (patch)
tree6872755fccedb331f4553c72b642c6c86a700bff /lib/axlsx/drawing/bar_series.rb
parent1c355c83a9603f835dfe59ef4473df2b8cc3534c (diff)
downloadcaxlsx-67aefd7705df82e43a8670102400a5abab49f6e8.tar.gz
caxlsx-67aefd7705df82e43a8670102400a5abab49f6e8.zip
Pipe output directly to str and avoid additional memory allocations
Currently, there are lots of examples of code like this, ``` str << ('<tag ' << foo << ' ' << bar << '/>') ``` 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.
Diffstat (limited to 'lib/axlsx/drawing/bar_series.rb')
-rw-r--r--lib/axlsx/drawing/bar_series.rb8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/axlsx/drawing/bar_series.rb b/lib/axlsx/drawing/bar_series.rb
index c744175f..483a0c43 100644
--- a/lib/axlsx/drawing/bar_series.rb
+++ b/lib/axlsx/drawing/bar_series.rb
@@ -62,15 +62,15 @@ module Axlsx
super(str) do
colors.each_with_index do |c, index|
str << '<c:dPt>'
- str << (+'<c:idx val="' << index.to_s << '"/>')
+ str << '<c:idx val="' << index.to_s << '"/>'
str << '<c:spPr><a:solidFill>'
- str << (+'<a:srgbClr val="' << c << '"/>')
+ str << '<a:srgbClr val="' << c << '"/>'
str << '</a:solidFill></c:spPr></c:dPt>'
end
if series_color
str << '<c:spPr><a:solidFill>'
- str << (+'<a:srgbClr val="' << series_color << '"/>')
+ str << '<a:srgbClr val="' << series_color << '"/>'
str << '</a:solidFill>'
str << '</c:spPr>'
end
@@ -78,7 +78,7 @@ module Axlsx
@labels.to_xml_string(str) unless @labels.nil?
@data.to_xml_string(str) unless @data.nil?
# this is actually only required for shapes other than box
- str << (+'<c:shape val="' << shape.to_s << '"></c:shape>')
+ str << '<c:shape val="' << shape.to_s << '"></c:shape>'
end
end