As I understand it, if I pass arguments to a vararg function like so:
function("a", "b", "c", "d")
a new Array will be created to hold them. But what about this:
val someStringArray<String> = ...
function(*someStringArray)
Is this “safe” in term of additional memory allocations and no temporary Array will be created or it works exactly the same as the first example and a new array is needed?
Spread operator always copies an array, so that neither the function nor its caller are required to make defensive copies of the array.
It might be possible for the compiler to optimize such copying away, for example when one vararg function passes its array to another vararg function and doesn’t use it itself after, however such optimization has not been baked yet.