-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
Add an extend()
method in Array
#1718
Comments
These already work: var a = [1, 2]
var b = [3, 4]
var c = a + b
print(c) and var a = [1, 2]
var b = [3, 4]
a += b
print(a) Both print:
If the reason of your proposal is the slowness of the I suspect it's because GDScript loosely translates |
I thought this is not efficient mainly because the new array is being created. |
and also I think this method would be convenient for beginners who switched from other languages where there is |
Related: godotengine/godot#11073 |
I think, this would be a nice addition. I just ran into this a few minutes ago:
Took me a while to realize, that += creates a new, local array in the "append_some" function. But well, thinking about that, the behavior makes sense. Having something like extend() or append_array() would be nice to have in such situations. |
Describe the project you are working on:
gdscript plugins
Describe the problem or limitation you are having in your project:
it seems
is faster than
(especially if you are working with large arrays), but noisier (less laconic, this is most noticeable when you have to repeat it often in the code).
Describe the feature / enhancement and how it helps to overcome the problem or limitation:
I think the built-in
extend()
method would be faster thanfor .. append()
gdscript loop and certainly faster thana+=b
and still look good.Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
If this enhancement will not be used often, can it be worked around with a few lines of script?:
or
push_back()
(it seems marginally faster thanappend()
)also
a.resize()
can be usedIs there a reason why this should be core and not an add-on in the asset library?:
this is a new
Array
methodThe text was updated successfully, but these errors were encountered: