1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-09 12:50:35 +00:00

Merge pull request #100944 from Nazarwadim/LocalVector_use_1.5x_growth_factor

Use 1.5x growth factor for LocalVector
This commit is contained in:
Thaddeus Crews
2025-04-21 08:24:22 -05:00
2 changed files with 12 additions and 12 deletions

View File

@@ -58,9 +58,7 @@ public:
// Must take a copy instead of a reference (see GH-31736). // Must take a copy instead of a reference (see GH-31736).
_FORCE_INLINE_ void push_back(T p_elem) { _FORCE_INLINE_ void push_back(T p_elem) {
if (unlikely(count == capacity)) { if (unlikely(count == capacity)) {
capacity = tight ? (capacity + 1) : MAX((U)1, capacity << 1); reserve(count + 1);
data = (T *)memrealloc(data, capacity * sizeof(T));
CRASH_COND_MSG(!data, "Out of memory");
} }
if constexpr (!std::is_trivially_constructible_v<T> && !force_trivial) { if constexpr (!std::is_trivially_constructible_v<T> && !force_trivial) {
@@ -145,10 +143,16 @@ public:
} }
_FORCE_INLINE_ bool is_empty() const { return count == 0; } _FORCE_INLINE_ bool is_empty() const { return count == 0; }
_FORCE_INLINE_ U get_capacity() const { return capacity; } _FORCE_INLINE_ U get_capacity() const { return capacity; }
_FORCE_INLINE_ void reserve(U p_size) { void reserve(U p_size) {
p_size = tight ? p_size : nearest_power_of_2_templated(p_size); if (p_size > capacity) {
if (tight) {
capacity = p_size;
} else {
capacity = MAX((U)2, capacity + ((1 + capacity) >> 1));
if (p_size > capacity) { if (p_size > capacity) {
capacity = p_size; capacity = p_size;
}
}
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");
} }
@@ -163,11 +167,7 @@ public:
} }
count = p_size; count = p_size;
} else if (p_size > count) { } else if (p_size > count) {
if (unlikely(p_size > capacity)) { reserve(p_size);
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");
}
if constexpr (!std::is_trivially_constructible_v<T> && !force_trivial) { if constexpr (!std::is_trivially_constructible_v<T> && !force_trivial) {
memnew_arr_placement(data + count, p_size - count); memnew_arr_placement(data + count, p_size - count);
} }

View File

@@ -625,7 +625,7 @@ public:
}; };
struct AttachmentReference { struct AttachmentReference {
static const uint32_t UNUSED = 0xffffffff; static constexpr uint32_t UNUSED = 0xffffffff;
uint32_t attachment = UNUSED; uint32_t attachment = UNUSED;
TextureLayout layout = TEXTURE_LAYOUT_UNDEFINED; TextureLayout layout = TEXTURE_LAYOUT_UNDEFINED;
BitField<TextureAspectBits> aspect = {}; BitField<TextureAspectBits> aspect = {};