Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid Array allocation in Channel.select(Tuple)
Browse files Browse the repository at this point in the history
straight-shoota committed Jan 15, 2023
1 parent 4e08bbc commit ab1930c
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
@@ -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

0 comments on commit ab1930c

Please sign in to comment.