summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorAndreaCatania <info@andreacatania.com>2021-01-11 13:25:55 +0100
committerAndreaCatania <info@andreacatania.com>2021-01-11 13:47:31 +0100
commit5ba60c17dd8c367202bc3ada3f2a1fec75d5971d (patch)
tree86633e3245cc6b7b81fd2caa8106c68655774c6d /core
parentc3b23f02031dbdc96afa09e40fe51ffe345038ef (diff)
Add function `LocalVector::remove_unordered`
Added LocalVector unit tests.
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) {