From 9900e563f9ea069d62eaf6dbf2b2ad4f9a237b03 Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Thu, 30 May 2019 23:44:44 -0700 Subject: [PATCH] (maint) Enable Performance/TimesMap Constructing an n-element Array where each element is generated by the block is about twice as fast as `n.times.map`[1]. [1] https://github.com/rubocop-hq/rubocop/pull/2583 --- .rubocop.yml | 3 --- benchmarks/function_loading/benchmarker.rb | 2 +- lib/puppet/pops/parser/heredoc_support.rb | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 5110b8536b0..6fb3f036c78 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -649,9 +649,6 @@ Style/TrailingUnderscoreVariable: Lint/LiteralInInterpolation: Enabled: false -Performance/TimesMap: - Enabled: false - Layout/InitialIndentation: Enabled: false diff --git a/benchmarks/function_loading/benchmarker.rb b/benchmarks/function_loading/benchmarker.rb index 5c23342f110..98fb844bf6e 100644 --- a/benchmarks/function_loading/benchmarker.rb +++ b/benchmarks/function_loading/benchmarker.rb @@ -97,7 +97,7 @@ def generate def dependencies_for(n) return [] if n == 0 - n.times.map do |m| + Array.new(n) do |m| {'name' => "tester-module#{m}", 'version_requirement' => '1.0.0'} end end diff --git a/lib/puppet/pops/parser/heredoc_support.rb b/lib/puppet/pops/parser/heredoc_support.rb index 82e820c3a8b..05c7473a48c 100644 --- a/lib/puppet/pops/parser/heredoc_support.rb +++ b/lib/puppet/pops/parser/heredoc_support.rb @@ -137,7 +137,7 @@ def heredoc_text(lines, leading, has_margin, remove_break) # simply leaves lines that have text in the margin untouched. # processed_lines = lines.collect {|s| s.gsub(leading_pattern, '') } - margin_per_line = processed_lines.length.times.map {|x| lines[x].length - processed_lines[x].length } + margin_per_line = Array.new(processed_lines.length) {|x| lines[x].length - processed_lines[x].length } lines = processed_lines else # Array with a 0 per line