summaryrefslogtreecommitdiff
path: root/core/templates
diff options
context:
space:
mode:
authorkleonc <9283098+kleonc@users.noreply.github.com>2022-08-08 20:54:17 +0200
committerRĂ©mi Verschelde <rverschelde@gmail.com>2023-05-12 12:11:41 +0200
commit4b11fc65f19e7bdef94a7af293498dcadd79cf56 (patch)
tree9df7ebfc1ef56158ee1b17f05b30093991fc00ee /core/templates
parentb7206e25bf1c74f02f950d22fe5ca82429f9dab4 (diff)
Make `LocalVector` respect its `tight` template parameter
(cherry picked from commit 0b944e1a68e60f4847f0614ac48ef27f21567fb2)
Diffstat (limited to 'core/templates')
-rw-r--r--core/templates/local_vector.h15
1 files changed, 3 insertions, 12 deletions
diff --git a/core/templates/local_vector.h b/core/templates/local_vector.h
index 5311a94987..22db3a5744 100644
--- a/core/templates/local_vector.h
+++ b/core/templates/local_vector.h
@@ -59,11 +59,7 @@ public:
_FORCE_INLINE_ void push_back(T p_elem) {
if (unlikely(count == capacity)) {
- if (capacity == 0) {
- capacity = 1;
- } else {
- capacity <<= 1;
- }
+ capacity = tight ? (capacity + 1) : MAX((U)1, capacity << 1);
data = (T *)memrealloc(data, capacity * sizeof(T));
CRASH_COND_MSG(!data, "Out of memory");
}
@@ -87,7 +83,7 @@ public:
}
/// Removes the item copying the last value into the position of the one to
- /// remove. It's generally faster than `remove`.
+ /// remove. It's generally faster than `remove_at`.
void remove_at_unordered(U p_index) {
ERR_FAIL_INDEX(p_index, count);
count--;
@@ -143,12 +139,7 @@ public:
count = p_size;
} else if (p_size > count) {
if (unlikely(p_size > capacity)) {
- if (capacity == 0) {
- capacity = 1;
- }
- while (capacity < p_size) {
- capacity <<= 1;
- }
+ capacity = tight ? p_size : nearest_power_of_2_templated(p_size);
data = (T *)memrealloc(data, capacity * sizeof(T));
CRASH_COND_MSG(!data, "Out of memory");
}