| 56 | } |
| 57 | |
| 58 | void vector_basic::grow_to(fl::size new_capacity) { |
| 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 | } |
| 96 | |
| 97 | void vector_basic::reserve_impl(fl::size n) { |
| 98 | if (n > mCapacity) { |
nothing calls this directly
no test coverage detected