Skip to content

Commit

Permalink
Fix slow compile times for big StaticArray
Browse files Browse the repository at this point in the history
  • Loading branch information
j8r committed Jun 15, 2020
1 parent f584ff6 commit 1213edf
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/static_array.cr
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ struct StaticArray(T, N)
# ```
# StaticArray(Int32, 3).new { |i| i * 2 } # => StaticArray[0, 2, 4]
# ```
def self.new(&block : Int32 -> T)
def self.new(& : Int32 -> T)
array = uninitialized self
N.times do |i|
array.to_unsafe[i] = yield i
end
buf = array.to_unsafe
{% for i in 0...N %}
buf[{{i.id}}] = yield {{i.id}}
{% end %}
array
end

Expand Down

0 comments on commit 1213edf

Please sign in to comment.