diff options
| author | Geremia Taglialatela <[email protected]> | 2023-06-05 15:53:15 +0200 |
|---|---|---|
| committer | Geremia Taglialatela <[email protected]> | 2023-06-05 17:27:41 +0200 |
| commit | 7fdbd745a2c914001a2174aeadae26b9c970ffaf (patch) | |
| tree | 9b1a440ef0bee0ecaaeb7c991dcc9d8639cb7b6d /lib | |
| parent | a2eeaeefca8deb3d26f3f8dc62976fe6bf1dafcf (diff) | |
| download | caxlsx-7fdbd745a2c914001a2174aeadae26b9c970ffaf.tar.gz caxlsx-7fdbd745a2c914001a2174aeadae26b9c970ffaf.zip | |
Fix Style/FormatString offenses
`Kernel#format` is faster and will avoid to allocate an array compared
to `String#%`.
```
IPS:
kernel_format: 3877614.2 i/s
string_percent: 3531475.0 i/s - 1.10x (± 0.00) slower
Memory:
kernel_format: 160 allocated
string_percent: 200 allocated - 1.25x more
```
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/axlsx/drawing/pic.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/drawing/view_3D.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/drawing/vml_drawing.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/util/accessors.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/util/validators.rb | 10 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/worksheet.rb | 4 |
6 files changed, 11 insertions, 11 deletions
diff --git a/lib/axlsx/drawing/pic.rb b/lib/axlsx/drawing/pic.rb index 150d6dc5..c9efb378 100644 --- a/lib/axlsx/drawing/pic.rb +++ b/lib/axlsx/drawing/pic.rb @@ -124,7 +124,7 @@ module Axlsx # The part name for this image used in serialization and relationship building # @return [String] def pn - "#{IMAGE_PN % [(index + 1), extname]}" + format(IMAGE_PN, index + 1, extname) end # The relationship object for this pic. diff --git a/lib/axlsx/drawing/view_3D.rb b/lib/axlsx/drawing/view_3D.rb index 9b3489a3..5b29b296 100644 --- a/lib/axlsx/drawing/view_3D.rb +++ b/lib/axlsx/drawing/view_3D.rb @@ -111,7 +111,7 @@ module Axlsx val = Axlsx.instance_values_for(self)[name] return "" if val.nil? - "<%s:%s val='%s'/>" % [namespace, Axlsx::camel(name, false), val] + format("<%s:%s val='%s'/>", namespace, Axlsx::camel(name, false), val) end end end diff --git a/lib/axlsx/drawing/vml_drawing.rb b/lib/axlsx/drawing/vml_drawing.rb index 364ce19a..15698486 100644 --- a/lib/axlsx/drawing/vml_drawing.rb +++ b/lib/axlsx/drawing/vml_drawing.rb @@ -14,7 +14,7 @@ module Axlsx # The part name for this vml drawing # @return [String] def pn - "#{VML_DRAWING_PN}" % (@comments.worksheet.index + 1) + VML_DRAWING_PN % (@comments.worksheet.index + 1) end # serialize the vml_drawing to xml. diff --git a/lib/axlsx/util/accessors.rb b/lib/axlsx/util/accessors.rb index d653e32f..dfc3b1cd 100644 --- a/lib/axlsx/util/accessors.rb +++ b/lib/axlsx/util/accessors.rb @@ -56,7 +56,7 @@ module Axlsx symbols.each do |symbol| attr_reader symbol - module_eval(SETTER % [symbol, validator, symbol], __FILE__, __LINE__) + module_eval(format(SETTER, symbol, validator, symbol), __FILE__, __LINE__) end end end diff --git a/lib/axlsx/util/validators.rb b/lib/axlsx/util/validators.rb index 48c12c13..1357f4f3 100644 --- a/lib/axlsx/util/validators.rb +++ b/lib/axlsx/util/validators.rb @@ -10,7 +10,7 @@ module Axlsx # @raise [ArgumentError] Raised if the value provided is not in the list of choices. # @return [Boolean] true if validation succeeds. def self.validate(name, choices, v) - raise ArgumentError, (ERR_RESTRICTION % [v.to_s, name, choices.inspect]) unless choices.include?(v) + raise ArgumentError, format(ERR_RESTRICTION, v.to_s, name, choices.inspect) unless choices.include?(v) true end @@ -31,7 +31,7 @@ module Axlsx else min < value && value < max end - raise ArgumentError, (ERR_RANGE % [value.inspect, min.to_s, max.to_s, inclusive]) unless passes + raise ArgumentError, format(ERR_RANGE, value.inspect, min.to_s, max.to_s, inclusive) unless passes end end @@ -41,7 +41,7 @@ module Axlsx # @param [Regexp] regex The regular expression to evaluate # @param [Any] v The value to validate. def self.validate(name, regex, v) - raise ArgumentError, (ERR_REGEX % [v.inspect, regex.to_s]) unless v.respond_to?(:to_s) && regex.match?(v.to_s) + raise ArgumentError, format(ERR_REGEX, v.inspect, regex.to_s) unless v.respond_to?(:to_s) && regex.match?(v.to_s) end end @@ -56,14 +56,14 @@ module Axlsx # @see validate_boolean def self.validate(name, types, v, other = false) if other.is_a?(Proc) && !other.call(v) - raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect]) + raise ArgumentError, format(ERR_TYPE, v.inspect, name, types.inspect) end v_class = v.is_a?(Class) ? v : v.class Array(types).each do |t| return if v_class <= t end - raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect]) + raise ArgumentError, format(ERR_TYPE, v.inspect, name, types.inspect) end end diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index 29a22db1..07221b3f 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -675,9 +675,9 @@ module Axlsx if parts.size > 2 raise ArgumentError, (ERR_CELL_REFERENCE_INVALID % cell_def) elsif parts.first.nil? - raise ArgumentError, (ERR_CELL_REFERENCE_MISSING_CELL % [cell_def.split(":").first, cell_def]) + raise ArgumentError, format(ERR_CELL_REFERENCE_MISSING_CELL, cell_def.split(":").first, cell_def) elsif parts.last.nil? - raise ArgumentError, (ERR_CELL_REFERENCE_MISSING_CELL % [cell_def.split(":").last, cell_def]) + raise ArgumentError, format(ERR_CELL_REFERENCE_MISSING_CELL, cell_def.split(":").last, cell_def) end range(*parts) |
