Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow pushing multiple values at once with arrays. #11762

Open
NeeEoo opened this issue Sep 5, 2024 · 2 comments
Open

Allow pushing multiple values at once with arrays. #11762

NeeEoo opened this issue Sep 5, 2024 · 2 comments

Comments

@NeeEoo
Copy link

NeeEoo commented Sep 5, 2024

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
@back2dos
Copy link
Member

back2dos commented Sep 10, 2024

I think I would propose an insertMany(pos:Int, args:Array<T>):Void; and then you can still have your pushAll as a special case of that, via static extension.

@NeeEoo
Copy link
Author

NeeEoo commented Sep 10, 2024

No other target supports insert multiple values at once, to my knowledge and more targets support pushing multiple. If we want i would think it would be better to have pushMultiple/pushMany and insertMultiple/insertMany

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants