Skip to content

Commit

Permalink
Add Array#unsafe_build
Browse files Browse the repository at this point in the history
This prepares the API for refactoring array literal instantiation
without a block scope.

crystal-lang#10009
  • Loading branch information
straight-shoota committed Dec 17, 2020
1 parent 4c5b326 commit 05eb413
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/array.cr
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ class Array(T)
ary
end

# :nodoc:
#
# This method is used by LiteralExpander to efficiently create an Array
# instance from a literal.
def self.unsafe_build(capacity : Int) : self
ary = Array(T).new(capacity)
ary.size = capacity
ary
end

# Equality. Returns `true` if each element in `self` is equal to each
# corresponding element in *other*.
#
Expand Down

0 comments on commit 05eb413

Please sign in to comment.