Skip to content

Commit

Permalink
(maint) Enable Performance/TimesMap
Browse files Browse the repository at this point in the history
Constructing an n-element Array where each element is generated by the block is
about twice as fast as `n.times.map`[1].

[1] rubocop/rubocop#2583
  • Loading branch information
joshcooper committed Oct 7, 2019
1 parent c9ed878 commit 9ee6c7f
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 5 deletions.
3 changes: 0 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -658,9 +658,6 @@ Style/TrailingUnderscoreVariable:
Lint/LiteralInInterpolation:
Enabled: false

Performance/TimesMap:
Enabled: false

Layout/InitialIndentation:
Enabled: false

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/function_loading/benchmarker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/pops/parser/heredoc_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,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
Expand Down

0 comments on commit 9ee6c7f

Please sign in to comment.