diff options
| author | Geremia Taglialatela <[email protected]> | 2023-06-15 09:20:31 +0200 |
|---|---|---|
| committer | Geremia Taglialatela <[email protected]> | 2023-06-15 09:20:31 +0200 |
| commit | 9e5bc61c60f8775150163d6d2da73d60083f0dbd (patch) | |
| tree | dccab6808cde0975e2cd32f69e234b3394b36b3e | |
| parent | ad87c51bf8c8f59a36514bb95dc6d3a582c6b2fd (diff) | |
| download | caxlsx-9e5bc61c60f8775150163d6d2da73d60083f0dbd.tar.gz caxlsx-9e5bc61c60f8775150163d6d2da73d60083f0dbd.zip | |
Fix Lint/UnusedBlockArgument offenses
Use `each_value` instead of `each` where possible. The performance gain
is minimal (3%).
```
Comparison:
each_value: 4105733.4 i/s
each: 3998011.4 i/s - 1.03x (± 0.00) slower
```
| -rw-r--r-- | .rubocop_todo.yml | 8 | ||||
| -rw-r--r-- | lib/axlsx/drawing/axes.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/pivot_table.rb | 4 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/sheet_view.rb | 2 |
4 files changed, 4 insertions, 12 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index fc0449d9..525fd031 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -61,14 +61,6 @@ Lint/NonLocalExitFromIterator: - 'lib/axlsx/util/validators.rb' # This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. -Lint/UnusedBlockArgument: - Exclude: - - 'lib/axlsx/drawing/axes.rb' - - 'lib/axlsx/workbook/worksheet/pivot_table.rb' - - 'lib/axlsx/workbook/worksheet/sheet_view.rb' - -# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods. Lint/UnusedMethodArgument: Exclude: diff --git a/lib/axlsx/drawing/axes.rb b/lib/axlsx/drawing/axes.rb index 010fe8cd..f63ef95d 100644 --- a/lib/axlsx/drawing/axes.rb +++ b/lib/axlsx/drawing/axes.rb @@ -32,7 +32,7 @@ module Axlsx def to_xml_string(str = +'', options = {}) if options[:ids] # CatAxis must come first in the XML (for Microsoft Excel at least) - sorted = axes.sort_by { |name, axis| axis.is_a?(CatAxis) ? 0 : 1 } + sorted = axes.sort_by { |_name, axis| axis.is_a?(CatAxis) ? 0 : 1 } sorted.each { |axis| str << '<c:axId val="' << axis[1].id.to_s << '"/>' } else axes.each { |axis| axis[1].to_xml_string(str) } diff --git a/lib/axlsx/workbook/worksheet/pivot_table.rb b/lib/axlsx/workbook/worksheet/pivot_table.rb index a75842cd..97c4515b 100644 --- a/lib/axlsx/workbook/worksheet/pivot_table.rb +++ b/lib/axlsx/workbook/worksheet/pivot_table.rb @@ -210,7 +210,7 @@ module Axlsx end str << '</rowFields>' str << '<rowItems count="' << rows.size.to_s << '">' - rows.size.times do |i| + rows.size.times do str << '<i/>' end str << '</rowItems>' @@ -220,7 +220,7 @@ module Axlsx str << '<colFields count="1"><field x="-2"/></colFields>' str << "<colItems count=\"#{data.size}\">" str << '<i><x/></i>' - data[1..-1].each_with_index do |datum_value, i| + (data.size - 1).times do |i| str << "<i i=\"#{i + 1}\"><x v=\"#{i + 1}\"/></i>" end str << '</colItems>' diff --git a/lib/axlsx/workbook/worksheet/sheet_view.rb b/lib/axlsx/workbook/worksheet/sheet_view.rb index 6138cbf7..ee19061a 100644 --- a/lib/axlsx/workbook/worksheet/sheet_view.rb +++ b/lib/axlsx/workbook/worksheet/sheet_view.rb @@ -198,7 +198,7 @@ module Axlsx serialized_attributes str str << '>' @pane.to_xml_string(str) if @pane - @selections.each do |key, selection| + @selections.each_value do |selection| selection.to_xml_string(str) end str << '</sheetView>' |
