Merge pull request #45458 from Calinou/doc-array-push-pop-front-performance

Document low performance of `Array.push_front()` and `Array.pop_front()`
This commit is contained in:
Rémi Verschelde 2021-01-26 00:27:08 +01:00 committed by GitHub
commit 3d1dd195d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -234,7 +234,9 @@
<argument index="0" name="value" type="Variant">
</argument>
<description>
Removes the first occurrence of a value from the array.
Removes the first occurrence of a value from the array. To remove an element by index, use [method remove] instead.
[b]Note:[/b] This method acts in-place and doesn't return a value.
[b]Note:[/b] On large arrays, this method will be slower if the removed element is close to the beginning of the array (index 0). This is because all elements placed after the removed element have to be reindexed.
</description>
</method>
<method name="find">
@ -323,6 +325,8 @@
</argument>
<description>
Inserts a new element at a given position in the array. The position must be valid, or at the end of the array ([code]pos == size()[/code]).
[b]Note:[/b] This method acts in-place and doesn't return a value.
[b]Note:[/b] On large arrays, this method will be slower if the inserted element is close to the beginning of the array (index 0). This is because all elements placed after the newly inserted element have to be reindexed.
</description>
</method>
<method name="invert">
@ -421,14 +425,15 @@
<return type="Variant">
</return>
<description>
Removes and returns the last element of the array. Returns [code]null[/code] if the array is empty, without printing an error message.
Removes and returns the last element of the array. Returns [code]null[/code] if the array is empty, without printing an error message. See also [method pop_front].
</description>
</method>
<method name="pop_front">
<return type="Variant">
</return>
<description>
Removes and returns the first element of the array. Returns [code]null[/code] if the array is empty, without printing an error message.
Removes and returns the first element of the array. Returns [code]null[/code] if the array is empty, without printing an error message. See also [method pop_back].
[b]Note:[/b] On large arrays, this method is much slower than [method pop_back] as it will reindex all the array's elements every time it's called. The larger the array, the slower [method pop_front] will be.
</description>
</method>
<method name="push_back">
@ -437,7 +442,7 @@
<argument index="0" name="value" type="Variant">
</argument>
<description>
Appends an element at the end of the array.
Appends an element at the end of the array. See also [method push_front].
</description>
</method>
<method name="push_front">
@ -446,7 +451,8 @@
<argument index="0" name="value" type="Variant">
</argument>
<description>
Adds an element at the beginning of the array.
Adds an element at the beginning of the array. See also [method push_back].
[b]Note:[/b] On large arrays, this method is much slower than [method push_back] as it will reindex all the array's elements every time it's called. The larger the array, the slower [method push_front] will be.
</description>
</method>
<method name="remove">
@ -455,7 +461,9 @@
<argument index="0" name="position" type="int">
</argument>
<description>
Removes an element from the array by index. If the index does not exist in the array, nothing happens.
Removes an element from the array by index. If the index does not exist in the array, nothing happens. To remove an element by searching for its value, use [method erase] instead.
[b]Note:[/b] This method acts in-place and doesn't return a value.
[b]Note:[/b] On large arrays, this method will be slower if the removed element is close to the beginning of the array (index 0). This is because all elements placed after the removed element have to be reindexed.
</description>
</method>
<method name="resize">