This instruction is similar to concatarray, but assumes the first object is already an array, and appends to it directly. This is different than concatarray, which will create a new array instead of appending to an existing array.
Additionally, for both concatarray and concattoarray, if the second argument cannot be converted to an array, then just push it onto the array, instead of creating a new array to wrap it, and then using concat array. This saves an array allocation in that case.
This allows f(*a, *a, *1) to allocate only a single array on the caller side (which can be reused on the callee side in the case of def f(*a)). Prior to this commit, f(*a, *a, *1) would generate 4 arrays:
Add concattoarray VM instruction
This instruction is similar to concatarray, but assumes the first
object is already an array, and appends to it directly. This is
different than concatarray, which will create a new array instead
of appending to an existing array.
Additionally, for both concatarray and concattoarray, if the second
argument cannot be converted to an array, then just push it onto
the array, instead of creating a new array to wrap it, and then
using concat array. This saves an array allocation in that case.
This allows
f(*a, *a, *1)to allocate only a single array on thecaller side (which can be reused on the callee side in the case of
def f(*a)). Prior to this commit,f(*a, *a, *1)would generate4 arrays:
Instructions Before for
a = []; f(*a, *a, *1):Instructions After for
a = []; f(*a, *a, *1):