haxe
haxe copied to clipboard
Allow pushing multiple values at once with arrays.
Currently you can only push a single value at a time.
However some targets like JavaScript support pushing multiple values at once, and this functionality could be easily implemented into hxcpp too.
Allowing multiple values to be pushed at once would improve performance, as platforms could preallocate the required space for the requested amount of items, rather than reallocating each time a value is pushed
This feature seems like a good candidate to add to Haxe 5.x.x
If we don't want to risk breaking programs by making it push(...val:T), we could make a new function named pushAll(...val:T)
Heres how to do it for different targets:
Javascript:
array.push(...values); // takes up to 65535 arguments
Python:
array.extend(values) # takes an array
Java:
// if ArrayList is used internally
array.addAll(values); // takes an array
PHP:
array_push($array, ...$values); // takes any amount of arguments