9#include "platforms/assert_defs.h"
32 bool heap_allocated =
false;
37 heap_allocated =
true;
51 fl::size new_capacity = (3 *
mCapacity) / 2;
52 if (new_capacity < n) {
71 FASTLED_ASSERT(
mResource !=
nullptr,
"memory_resource is null");
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");
157 mOps->copy_construct(dst, element);
167 FASTLED_ASSERT(
mArray !=
nullptr,
"mArray null after ensure_capacity in push_back_move");
170 mOps->move_construct(dst, element);
178 if (
mSize == 0)
return;
201 if (index >=
mSize)
return;
206 if (count == 0 || first_index >=
mSize)
return;
207 if (first_index + count >
mSize) {
208 count =
mSize - first_index;
211 fl::size remaining =
mSize - first_index - count;
215 for (fl::size i = 0; i < count; ++i) {
219 for (fl::size i = 0; i < remaining; ++i) {
222 mOps->move_construct(dst, src);
249 for (fl::size i =
mSize - 1; i > index; --i) {
278 for (fl::size i =
mSize - 1; i > index; --i) {
298 if (n ==
mSize)
return;
303 for (fl::size i = n; i <
mSize; ++i) {
316 if (
mOps->default_construct) {
317 for (fl::size i =
mSize; i < n; ++i) {
331 if (n ==
mSize)
return;
335 for (fl::size i = n; i <
mSize; ++i) {
347 for (fl::size i =
mSize; i < n; ++i) {
351 for (fl::size i =
mSize; i < n; ++i) {
367 bool other_inline = other.
isInline();
369 if (!this_inline && !other_inline) {
378 }
else if (this_inline && other_inline) {
381 for (fl::size i = 0; i <
max_size; ++i) {
388 }
else if (i <
mSize) {
406 }
else if (this_inline) {
410 void* other_array = other.
mArray;
445 fl::size tmp_size =
mSize;
447 other.
mSize = tmp_size;
459 if (other.mSize == 0)
return;
465 for (fl::size i = 0; i < other.mSize; ++i) {
475 if (other.isInline()) {
479 mOps->uninitialized_move_n(
mArray, other.mArray, other.mSize);
481 if (other.mSize > 0) {
496 if (other.hasInlineBuffer()) {
497 other.mArray = other.inlineBufferPtr();
498 other.mCapacity = other.mInlineCapacity;
500 other.mArray =
nullptr;
508 if (
this == &other)
return;
Type-erased base class for fl::vector<T>.
void * allocate(fl::size bytes) FL_NOEXCEPT
Polymorphic memory resource base class (PMR-style).
void resize_value_impl(fl::size n, const void *value) FL_NOEXCEPT
Resize to n elements. New elements are copy-constructed from value.
void resize_impl(fl::size n) FL_NOEXCEPT
Resize to n elements. New elements are default-constructed (zeroed for trivial).
void grow_to(fl::size new_capacity) FL_NOEXCEPT
Grow to new_capacity. Moves existing elements.
void erase_impl(fl::size index) FL_NOEXCEPT
Erase element at index. Shifts subsequent elements left.
const vector_element_ops * mOps
void reserve_impl(fl::size n) FL_NOEXCEPT
bool hasInlineBuffer() const FL_NOEXCEPT
Does this vector have an inline buffer at all?
void trivial_default_construct(void *ptr, fl::size count) const FL_NOEXCEPT
void push_back_move_impl(void *element) FL_NOEXCEPT
void shrink_to_fit_impl() FL_NOEXCEPT
bool isInline() const FL_NOEXCEPT
Is data currently in the inline buffer?
void insert_move_impl(fl::size index, void *element) FL_NOEXCEPT
Insert element at index by move. Shifts subsequent elements right.
memory_resource * mResource
void trivial_swap(void *a, void *b) const FL_NOEXCEPT
void move_from(vector_basic &other) FL_NOEXCEPT
Move-steal contents from another vector_basic.
void trivial_copy(void *dst, const void *src, fl::size count) const FL_NOEXCEPT
vector_basic(fl::size elementSize, memory_resource *resource, const vector_element_ops *ops) FL_NOEXCEPT
Heap-only vector (no inline buffer).
void ensure_capacity(fl::size n) FL_NOEXCEPT
Ensure capacity for at least n elements. Grows if needed.
void insert_copy_impl(fl::size index, const void *element) FL_NOEXCEPT
Insert element at index by copy. Shifts subsequent elements right.
void move_assign(vector_basic &other) FL_NOEXCEPT
Move-assign from another vector_basic (clears this first).
void * element_ptr(fl::size index) FL_NOEXCEPT
Pointer to element at index (byte arithmetic).
void * inlineBufferPtr() FL_NOEXCEPT
Compute inline buffer pointer from offset.
void copy_from(const vector_basic &other) FL_NOEXCEPT
Copy all elements from another vector_basic.
void clear_impl() FL_NOEXCEPT
void trivial_move_left(void *dst, const void *src, fl::size count) const FL_NOEXCEPT
~vector_basic() FL_NOEXCEPT
void swap_impl(vector_basic &other) FL_NOEXCEPT
Swap contents with another vector_basic.
void pop_back_impl() FL_NOEXCEPT
void push_back_copy_impl(const void *element) FL_NOEXCEPT
void erase_range_impl(fl::size first_index, fl::size count) FL_NOEXCEPT
Erase range [first_index, first_index + count).
void * memcpy(void *dest, const void *src, size_t n) FL_NOEXCEPT
constexpr int type_rank< T >::value
void * memset(void *s, int c, size_t n) FL_NOEXCEPT
void * memmove(void *dest, const void *src, size_t n) FL_NOEXCEPT
expected< T, E > result
Alias for expected (Rust-style naming)
Base definition for an LED controller.