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

◆ ensure_capacity()

template<typename T, typename Allocator = fl::allocator<T>>
void fl::deque< T, Allocator >::ensure_capacity ( fl::size min_capacity)
inlineprivate

Definition at line 27 of file deque.h.

27 {
28 if (mCapacity >= min_capacity) {
29 return;
30 }
31
33 while (new_capacity < min_capacity) {
34 new_capacity *= 2;
35 }
36
37 T* new_data = mAlloc.allocate(new_capacity);
38 if (!new_data) {
39 return; // Allocation failed
40 }
41
42 // Copy existing elements to new buffer in linear order
43 for (fl::size i = 0; i < mSize; ++i) {
45 mAlloc.construct(&new_data[i], fl::move(mData[old_idx]));
46 mAlloc.destroy(&mData[old_idx]);
47 }
48
49 if (mData) {
50 mAlloc.deallocate(mData, mCapacity);
51 }
52
55 mFront = 0; // Reset front to 0 after reallocation
56 }
T * mData
Definition deque.h:19
fl::size mFront
Definition deque.h:22
fl::size mCapacity
Definition deque.h:20
fl::size mSize
Definition deque.h:21
Allocator mAlloc
Definition deque.h:23
static const fl::size kInitialCapacity
Definition deque.h:25

Referenced by fl::deque< int >::push_back(), fl::deque< int >::push_back(), fl::deque< int >::push_front(), fl::deque< int >::push_front(), and fl::deque< int >::resize().

+ Here is the caller graph for this function: