Skip to content

Commit

Permalink
Avoid Array allocation in Channel.select(Tuple)
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Jan 15, 2023
1 parent 440b62d commit cc33631
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/channel.cr
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,11 @@ class Channel(T)
# * `StaticArray`: This avoids a heap allocation because we can dup a
# static array on the stack.
ops_locks = ops.dup
elsif ops.responds_to?(:to_static_array)
# If the collection type implements `to_static_array` we can create a
# copy without allocating an array. This applies to `Tuple` types, which
# the compiler generates for `select` expressions.
ops_locks = ops.to_static_array
else
ops_locks = ops.to_a
end
Expand Down

0 comments on commit cc33631

Please sign in to comment.