Skip to content

Commit

Permalink
Merge pull request #64120 from kleonc/local-vector-tight
Browse files Browse the repository at this point in the history
Make `LocalVector` respect its `tight` template parameter
  • Loading branch information
akien-mga committed May 8, 2023
2 parents bbe05b6 + 0b944e1 commit cb6308e
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions core/templates/local_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ class LocalVector {

_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");
}
Expand All @@ -87,7 +83,7 @@ class LocalVector {
}

/// 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--;
Expand Down Expand Up @@ -143,12 +139,7 @@ class LocalVector {
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");
}
Expand Down

0 comments on commit cb6308e

Please sign in to comment.