diff --git a/src/channel.cr b/src/channel.cr index 999e0af6855d..74010d9c2c15 100644 --- a/src/channel.cr +++ b/src/channel.cr @@ -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