diff options
| author | Geremia Taglialatela <[email protected]> | 2023-05-10 17:25:51 +0200 |
|---|---|---|
| committer | Geremia Taglialatela <[email protected]> | 2023-05-10 17:25:51 +0200 |
| commit | 7139d6252ad775ea9b6ffe2b2372e86c1c825401 (patch) | |
| tree | 1402fc2368cf9245459db84b1c6700ad0ce6f971 | |
| parent | 67d8a1a781e53761a483575cc5abc7e9a992d2ca (diff) | |
| download | caxlsx-7139d6252ad775ea9b6ffe2b2372e86c1c825401.tar.gz caxlsx-7139d6252ad775ea9b6ffe2b2372e86c1c825401.zip | |
Fix Inefficient Hash Search offenses
Use `key?` instead of `keys.include?` to improve performance
| -rw-r--r-- | .rubocop_todo.yml | 8 | ||||
| -rw-r--r-- | lib/axlsx/drawing/axes.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/drawing/d_lbls.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/stylesheet/styles.rb | 4 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/worksheet.rb | 2 |
5 files changed, 5 insertions, 13 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8f8f4bd7..453d26fc 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -112,14 +112,6 @@ Performance/Detect: Exclude: - 'lib/axlsx/workbook/workbook.rb' -# This cop supports unsafe autocorrection (--autocorrect-all). -Performance/InefficientHashSearch: - Exclude: - - 'lib/axlsx/drawing/axes.rb' - - 'lib/axlsx/drawing/d_lbls.rb' - - 'lib/axlsx/stylesheet/styles.rb' - - 'lib/axlsx/workbook/worksheet/worksheet.rb' - # This cop supports safe autocorrection (--autocorrect). Performance/RedundantBlockCall: Exclude: diff --git a/lib/axlsx/drawing/axes.rb b/lib/axlsx/drawing/axes.rb index eb4728c6..6a74c879 100644 --- a/lib/axlsx/drawing/axes.rb +++ b/lib/axlsx/drawing/axes.rb @@ -9,7 +9,7 @@ module Axlsx # class of the axis type to construct. The :cat_axis, if there is one, # must come first (we assume a Ruby 1.9+ Hash or an OrderedHash). def initialize(options = {}) - raise(ArgumentError, "CatAxis must come first") if options.keys.include?(:cat_axis) && options.keys.first != :cat_axis + raise(ArgumentError, "CatAxis must come first") if options.key?(:cat_axis) && options.keys.first != :cat_axis options.each do |name, axis_class| add_axis(name, axis_class) diff --git a/lib/axlsx/drawing/d_lbls.rb b/lib/axlsx/drawing/d_lbls.rb index 4e2bd40c..29697378 100644 --- a/lib/axlsx/drawing/d_lbls.rb +++ b/lib/axlsx/drawing/d_lbls.rb @@ -76,7 +76,7 @@ module Axlsx str << '<c:dLbls>' instance_vals = Axlsx.instance_values_for(self) %w(d_lbl_pos show_legend_key show_val show_cat_name show_ser_name show_percent show_bubble_size show_leader_lines).each do |key| - next unless instance_vals.keys.include?(key) && instance_vals[key] != nil + next unless instance_vals.key?(key) && instance_vals[key] != nil str << "<c:#{Axlsx::camel(key, false)} val='#{instance_vals[key]}' />" end diff --git a/lib/axlsx/stylesheet/styles.rb b/lib/axlsx/stylesheet/styles.rb index 7b44c023..e8263b45 100644 --- a/lib/axlsx/stylesheet/styles.rb +++ b/lib/axlsx/stylesheet/styles.rb @@ -329,7 +329,7 @@ module Axlsx Axlsx.instance_values_for(fonts.first).each do |key, value| # Thanks for that 1.8.7 - cant do a simple merge... - options[key.to_sym] = value unless options.keys.include?(key.to_sym) + options[key.to_sym] = value unless options.key?(key.to_sym) end font = Font.new(options) font.color = Color.new(:rgb => options[:fg_color]) if options[:fg_color] @@ -383,7 +383,7 @@ module Axlsx end validate_border_hash = ->(val) { - if !(val.keys.include?(:style) && val.keys.include?(:color)) + if !(val.key?(:style) && val.key?(:color)) raise ArgumentError, (ERR_INVALID_BORDER_OPTIONS % options[:border]) end } diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index 8c3514cc..960f33b3 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -187,7 +187,7 @@ module Axlsx # @return Boolean # @see #page_setup def fit_to_page? - return false unless Axlsx.instance_values_for(self).keys.include?('page_setup') + return false unless Axlsx.instance_values_for(self).key?('page_setup') page_setup.fit_to_page? end |
