Make LocalVector respect its tight template parameter

(cherry picked from commit 0b944e1a68)
This commit is contained in:
kleonc
2022-08-08 20:54:17 +02:00
committed by Rémi Verschelde
parent b7206e25bf
commit 4b11fc65f1

View File

@@ -59,11 +59,7 @@ public:
_FORCE_INLINE_ void push_back(T p_elem) { _FORCE_INLINE_ void push_back(T p_elem) {
if (unlikely(count == capacity)) { if (unlikely(count == capacity)) {
if (capacity == 0) { capacity = tight ? (capacity + 1) : MAX((U)1, capacity << 1);
capacity = 1;
} else {
capacity <<= 1;
}
data = (T *)memrealloc(data, capacity * sizeof(T)); data = (T *)memrealloc(data, capacity * sizeof(T));
CRASH_COND_MSG(!data, "Out of memory"); 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 /// 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) { void remove_at_unordered(U p_index) {
ERR_FAIL_INDEX(p_index, count); ERR_FAIL_INDEX(p_index, count);
count--; count--;
@@ -143,12 +139,7 @@ public:
count = p_size; count = p_size;
} else if (p_size > count) { } else if (p_size > count) {
if (unlikely(p_size > capacity)) { if (unlikely(p_size > capacity)) {
if (capacity == 0) { capacity = tight ? p_size : nearest_power_of_2_templated(p_size);
capacity = 1;
}
while (capacity < p_size) {
capacity <<= 1;
}
data = (T *)memrealloc(data, capacity * sizeof(T)); data = (T *)memrealloc(data, capacity * sizeof(T));
CRASH_COND_MSG(!data, "Out of memory"); CRASH_COND_MSG(!data, "Out of memory");
} }