From 5ba60c17dd8c367202bc3ada3f2a1fec75d5971d Mon Sep 17 00:00:00 2001 From: AndreaCatania Date: Mon, 11 Jan 2021 13:25:55 +0100 Subject: Add function `LocalVector::remove_unordered` Added LocalVector unit tests. --- core/templates/local_vector.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'core') 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) { -- cgit v1.2.3