FastLED 3.9.15
Loading...
Searching...
No Matches

◆ resize_impl()

void fl::vector_basic::resize_impl ( fl::size n)

Resize to n elements. New elements are default-constructed (zeroed for trivial).

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

297 {
298 if (n == mSize) return;
299
300 if (n < mSize) {
301 // Shrink: destroy excess elements
302 if (mOps) {
303 for (fl::size i = n; i < mSize; ++i) {
304 mOps->destroy(element_ptr(i));
305 }
306 }
307 mSize = n;
308 return;
309 }
310
311 // Grow: ensure capacity and default-construct new elements
313 if (mCapacity < n) return; // allocation failed
314
315 if (mOps) {
316 if (mOps->default_construct) {
317 for (fl::size i = mSize; i < n; ++i) {
318 mOps->default_construct(element_ptr(i));
319 }
320 } else {
321 // Type has no default constructor — zero-fill as fallback
323 }
324 } else {
326 }
327 mSize = n;
328}
const vector_element_ops * mOps
void trivial_default_construct(void *ptr, fl::size count) const FL_NOEXCEPT
void ensure_capacity(fl::size n) FL_NOEXCEPT
Ensure capacity for at least n elements. Grows if needed.
void * element_ptr(fl::size index) FL_NOEXCEPT
Pointer to element at index (byte arithmetic).

References element_ptr(), ensure_capacity(), mCapacity, mOps, mSize, and trivial_default_construct().

Referenced by fl::vector< fl::i16 >::resize().

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