FastLED 3.9.15
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 58 of file basic_vector.cpp.hpp.

58 {
59 // PATH 1: Try in-place reallocate if on heap and trivially copyable
60 if (!isInline() && mArray && !mOps) {
61 void* result = mResource->reallocate(mArray, mCapacity * mElementSize,
62 new_capacity * mElementSize);
63 if (result) {
64 mArray = result;
65 mCapacity = new_capacity;
66 return;
67 }
68 }
69
70 // PATH 2: Allocate new buffer, move elements, free old
71 FASTLED_ASSERT(mResource != nullptr, "memory_resource is null");
72 fl::size alloc_bytes = new_capacity * mElementSize;
73 FASTLED_ASSERT(alloc_bytes > 0, "zero allocation in grow_to");
74 void* new_buf = mResource->allocate(alloc_bytes);
75 FASTLED_ASSERT(new_buf != nullptr, "allocation failed in grow_to");
76 if (!new_buf) return;
77
78 // Move existing elements to new buffer
79 if (mSize > 0 && mArray) {
80 if (mOps) {
81 mOps->uninitialized_move_n(new_buf, mArray, mSize);
82 mOps->destroy_n(mArray, mSize);
83 } else {
84 trivial_copy(new_buf, mArray, mSize);
85 }
86 }
87
88 // Free old buffer (only if it's on the heap, not inline)
89 if (!isInline() && mArray) {
90 mResource->deallocate(mArray, mCapacity * mElementSize);
91 }
92
93 mArray = new_buf;
94 mCapacity = new_capacity;
95}
const vector_element_ops * mOps
bool isInline() const FL_NOEXCEPT
Is data currently in the inline buffer?
fl::size mElementSize
memory_resource * mResource
void trivial_copy(void *dst, const void *src, fl::size count) const FL_NOEXCEPT
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31

References isInline(), mArray, mCapacity, mElementSize, mOps, mResource, mSize, and trivial_copy().

Referenced by ensure_capacity(), and reserve_impl().

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