summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/workbook/worksheet/data_validation.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/workbook/worksheet/data_validation.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/workbook/worksheet/data_validation.rb')
-rw-r--r--lib/axlsx/workbook/worksheet/data_validation.rb10
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/axlsx/workbook/worksheet/data_validation.rb b/lib/axlsx/workbook/worksheet/data_validation.rb
index 1b9cb46a..d5fa5908 100644
--- a/lib/axlsx/workbook/worksheet/data_validation.rb
+++ b/lib/axlsx/workbook/worksheet/data_validation.rb
@@ -237,12 +237,12 @@ module Axlsx
valid_attributes = get_valid_attributes
str << '<dataValidation '
- str << Axlsx.instance_values_for(self).map do |key, value|
- +'' << key << '="' << Axlsx.booleanize(value).to_s << '"' if (valid_attributes.include?(key.to_sym) && !CHILD_ELEMENTS.include?(key.to_sym))
- end.join(' ')
+ Axlsx.instance_values_for(self).each do |key, value|
+ str << key << '="' << Axlsx.booleanize(value).to_s << '" ' if (valid_attributes.include?(key.to_sym) && !CHILD_ELEMENTS.include?(key.to_sym))
+ end
str << '>'
- str << (+'<formula1>' << self.formula1 << '</formula1>') if @formula1 and valid_attributes.include?(:formula1)
- str << (+'<formula2>' << self.formula2 << '</formula2>') if @formula2 and valid_attributes.include?(:formula2)
+ str << '<formula1>' << self.formula1 << '</formula1>' if @formula1 and valid_attributes.include?(:formula1)
+ str << '<formula2>' << self.formula2 << '</formula2>' if @formula2 and valid_attributes.include?(:formula2)
str << '</dataValidation>'
end