Skip to content

Commit

Permalink
Use 1.5x growth factor for LocalVector
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazarwadim committed Jan 7, 2025
1 parent 2582793 commit 77217fe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
28 changes: 20 additions & 8 deletions core/templates/local_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,9 @@ class LocalVector {
return data;
}

_FORCE_INLINE_ void push_back(T p_elem) {
_FORCE_INLINE_ void push_back(const T &p_elem) {
if (unlikely(count == capacity)) {
capacity = tight ? (capacity + 1) : MAX((U)1, capacity << 1);
data = (T *)memrealloc(data, capacity * sizeof(T));
CRASH_COND_MSG(!data, "Out of memory");
reserve(count + 1);
}

if constexpr (!std::is_trivially_constructible_v<T> && !force_trivial) {
Expand Down Expand Up @@ -137,10 +135,16 @@ class LocalVector {
}
_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 = tight ? p_size : nearest_power_of_2_templated(p_size);
void reserve(U p_size) {
if (p_size > capacity) {
capacity = p_size;
if (tight) {
capacity = p_size;
} else {
capacity = MAX((U)2, capacity + ((1 + capacity) >> 1));
if (p_size > capacity) {
capacity = p_size;
}
}
data = (T *)memrealloc(data, capacity * sizeof(T));
CRASH_COND_MSG(!data, "Out of memory");
}
Expand All @@ -157,7 +161,15 @@ class LocalVector {
count = p_size;
} else if (p_size > count) {
if (unlikely(p_size > capacity)) {
capacity = tight ? p_size : nearest_power_of_2_templated(p_size);
if (tight) {
capacity = p_size;
} else {
capacity = MAX((U)2, capacity + ((1 + capacity) >> 1));
if (p_size > capacity) {
capacity = p_size;
}
}

data = (T *)memrealloc(data, capacity * sizeof(T));
CRASH_COND_MSG(!data, "Out of memory");
}
Expand Down
2 changes: 1 addition & 1 deletion servers/rendering/rendering_device_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ class RenderingDeviceDriver : public RenderingDeviceCommons {
};

struct AttachmentReference {
static const uint32_t UNUSED = 0xffffffff;
static constexpr uint32_t UNUSED = 0xffffffff;
uint32_t attachment = UNUSED;
TextureLayout layout = TEXTURE_LAYOUT_UNDEFINED;
BitField<TextureAspectBits> aspect;
Expand Down

0 comments on commit 77217fe

Please sign in to comment.