FastLED 3.10.8
Loading...
Searching...
No Matches

◆ grow_to()

void fl::vector_basic::grow_to ( fl::size new_capacity)
private

Grow to new_capacity. Moves existing elements.

Definition at line 71 of file basic_vector.cpp.hpp.

71 {
72 // PATH 1: Try in-place reallocate if on heap and trivially copyable
73 if (!isInline() && mArray && !mOps) {
74 void* result = mResource->reallocate(mArray, mCapacity * mElementSize,
75 new_capacity * mElementSize);
76 if (result) {
77 mArray = result;
78 mCapacity = new_capacity;
79 return;
80 }
81 }
82
83 // PATH 2: Allocate new buffer, move elements, free old
84 FASTLED_ASSERT(mResource != nullptr, "memory_resource is null");
85 fl::size alloc_bytes = new_capacity * mElementSize;
86 FASTLED_ASSERT(alloc_bytes > 0, "zero allocation in grow_to");
87 void* new_buf = mResource->allocate(alloc_bytes);
88 // Allocation failure is recoverable: callers detect unchanged capacity.
89 if (!new_buf) return;
90
91 // Move existing elements to new buffer
92 if (mSize > 0 && mArray) {
93 if (mOps) {
95 mOps->destroy_n(mArray, mSize);
96 } else {
97 trivial_copy(new_buf, mArray, mSize);
98 }
99 }
100
101 // Free old buffer (only if it's on the heap, not inline)
102 if (!isInline() && mArray) {
103 mResource->deallocate(mArray, mCapacity * mElementSize);
104 }
105
106 mArray = new_buf;
107 mCapacity = new_capacity;
108}
const vector_element_ops * mOps
void trivial_copy(void *dst, const void *src, fl::size count) const FL_NO_EXCEPT
bool isInline() const FL_NO_EXCEPT
Is data currently in the inline buffer?
fl::size mElementSize
memory_resource * mResource
void uninitialized_move_n_impl(void *dst, void *src, fl::size count) const FL_NO_EXCEPT
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31

References fl::FL_NO_EXCEPT, isInline(), mArray, mCapacity, mElementSize, mOps, mResource, mSize, trivial_copy(), and uninitialized_move_n_impl().

Referenced by ensure_capacity(), and reserve_impl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: