Skip to content

Commit

Permalink
Merge pull request #2403 from eregon/use-array-new
Browse files Browse the repository at this point in the history
Prefer `Array.new(n) {}` to `n.times.map {}`
  • Loading branch information
kddnewton authored Feb 14, 2024
2 parents d00c1bb + debef8c commit b68effc
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions templates/lib/prism/serialize.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ module Prism
end

def load_line_offsets
source.instance_variable_set :@offsets, load_varuint.times.map { load_varuint }
source.instance_variable_set :@offsets, Array.new(load_varuint) { load_varuint }
end

def load_comments
load_varuint.times.map do
Array.new(load_varuint) do
case load_varuint
when 0 then InlineComment.new(load_location)
when 1 then EmbDocComment.new(load_location)
Expand All @@ -98,10 +98,10 @@ module Prism

def load_metadata
comments = load_comments
magic_comments = load_varuint.times.map { MagicComment.new(load_location, load_location) }
magic_comments = Array.new(load_varuint) { MagicComment.new(load_location, load_location) }
data_loc = load_optional_location
errors = load_varuint.times.map { ParseError.new(load_embedded_string, load_location, load_error_level) }
warnings = load_varuint.times.map { ParseWarning.new(load_embedded_string, load_location, load_warning_level) }
errors = Array.new(load_varuint) { ParseError.new(load_embedded_string, load_location, load_error_level) }
warnings = Array.new(load_varuint) { ParseWarning.new(load_embedded_string, load_location, load_warning_level) }
[comments, magic_comments, data_loc, errors, warnings]
end

Expand Down

0 comments on commit b68effc

Please sign in to comment.