diff options
| author | Paul Kmiec <[email protected]> | 2023-05-05 08:58:17 -0700 |
|---|---|---|
| committer | Paul Kmiec <[email protected]> | 2023-05-05 09:29:58 -0700 |
| commit | 67aefd7705df82e43a8670102400a5abab49f6e8 (patch) | |
| tree | 6872755fccedb331f4553c72b642c6c86a700bff /lib/axlsx/drawing/chart.rb | |
| parent | 1c355c83a9603f835dfe59ef4473df2b8cc3534c (diff) | |
| download | caxlsx-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/chart.rb')
| -rw-r--r-- | lib/axlsx/drawing/chart.rb | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/axlsx/drawing/chart.rb b/lib/axlsx/drawing/chart.rb index 300a5086..436319fb 100644 --- a/lib/axlsx/drawing/chart.rb +++ b/lib/axlsx/drawing/chart.rb @@ -206,13 +206,13 @@ module Axlsx # @return [String] def to_xml_string(str = +'') str << '<?xml version="1.0" encoding="UTF-8"?>' - str << (+'<c:chartSpace xmlns:c="' << XML_NS_C << '" xmlns:a="' << XML_NS_A << '" xmlns:r="' << XML_NS_R << '">') - str << (+'<c:date1904 val="' << Axlsx::Workbook.date1904.to_s << '"/>') - str << (+'<c:roundedCorners val="' << rounded_corners.to_s << '"/>') - str << (+'<c:style val="' << style.to_s << '"/>') + str << '<c:chartSpace xmlns:c="' << XML_NS_C << '" xmlns:a="' << XML_NS_A << '" xmlns:r="' << XML_NS_R << '">' + str << '<c:date1904 val="' << Axlsx::Workbook.date1904.to_s << '"/>' + str << '<c:roundedCorners val="' << rounded_corners.to_s << '"/>' + str << '<c:style val="' << style.to_s << '"/>' str << '<c:chart>' @title.to_xml_string(str) unless @title.empty? - str << (+'<c:autoTitleDeleted val="' << @title.nil?.to_s << '"/>') + str << '<c:autoTitleDeleted val="' << @title.nil?.to_s << '"/>' @view_3D.to_xml_string(str) if @view_3D str << '<c:floor><c:thickness val="0"/></c:floor>' str << '<c:sideWall><c:thickness val="0"/></c:sideWall>' @@ -223,13 +223,13 @@ module Axlsx str << '</c:plotArea>' if @show_legend str << '<c:legend>' - str << (+'<c:legendPos val="' << @legend_position.to_s << '"/>') + str << '<c:legendPos val="' << @legend_position.to_s << '"/>' str << '<c:layout/>' str << '<c:overlay val="0"/>' str << '</c:legend>' end - str << (+'<c:plotVisOnly val="' << @plot_visible_only.to_s << '"/>') - str << (+'<c:dispBlanksAs val="' << display_blanks_as.to_s << '"/>') + str << '<c:plotVisOnly val="' << @plot_visible_only.to_s << '"/>' + str << '<c:dispBlanksAs val="' << display_blanks_as.to_s << '"/>' str << '<c:showDLblsOverMax val="1"/>' str << '</c:chart>' if bg_color |
