summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-01-11 14:48:00 +0100
committerGitHub <noreply@github.com>2021-01-11 14:48:00 +0100
commitc26510359acda20834e06e4446905393d165bdf4 (patch)
treed0a0c193d9150e129ba52c21a731f56c23511893 /core
parentf414a323b168896a7350638d621636cd89b38c42 (diff)
parent5ba60c17dd8c367202bc3ada3f2a1fec75d5971d (diff)
Merge pull request #42270 from AndreaCatania/AndreaCatania-patch-4
Added the function `remove_unordered` to the LocalVector container.
Diffstat (limited to 'core')
-rw-r--r--core/templates/local_vector.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/core/templates/local_vector.h b/core/templates/local_vector.h
index 4ffb93b2ad..ffd17b7ee9 100644
--- a/core/templates/local_vector.h
+++ b/core/templates/local_vector.h
@@ -82,6 +82,19 @@ public:
}
}
+ /// Removes the item copying the last value into the position of the one to
+ /// remove. It's generally faster than `remove`.
+ void remove_unordered(U p_index) {
+ ERR_FAIL_INDEX(p_index, count);
+ count--;
+ if (count > p_index) {
+ data[p_index] = data[count];
+ }
+ if (!__has_trivial_destructor(T) && !force_trivial) {
+ data[count].~T();
+ }
+ }
+
void erase(const T &p_val) {
int64_t idx = find(p_val);
if (idx >= 0) {
@@ -105,6 +118,7 @@ public:
}
}
_FORCE_INLINE_ bool is_empty() const { return count == 0; }
+ _FORCE_INLINE_ U get_capacity() const { return capacity; }
_FORCE_INLINE_ void reserve(U p_size) {
p_size = nearest_power_of_2_templated(p_size);
if (p_size > capacity) {