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

◆ shrink_to_fit_impl()

void fl::vector_basic::shrink_to_fit_impl ( )

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

103 {
104 if (mSize == 0) {
105 if (!isInline() && mArray) {
106 mResource->deallocate(mArray, mCapacity * mElementSize);
107 }
108 if (hasInlineBuffer()) {
111 } else {
112 mArray = nullptr;
113 mCapacity = 0;
114 }
115 return;
116 }
117
118 // If data fits in inline buffer and we're on heap, move back to inline
119 if (hasInlineBuffer() && !isInline() && mSize <= mInlineCapacity) {
120 void* inline_buf = inlineBufferPtr();
121 if (mOps) {
122 mOps->uninitialized_move_n(inline_buf, mArray, mSize);
123 mOps->destroy_n(mArray, mSize);
124 } else {
125 trivial_copy(inline_buf, mArray, mSize);
126 }
127 mResource->deallocate(mArray, mCapacity * mElementSize);
128 mArray = inline_buf;
130 return;
131 }
132
133 // Shrink heap allocation
134 if (!isInline() && mCapacity > mSize) {
135 void* new_buf = mResource->allocate(mSize * mElementSize);
136 if (new_buf) {
137 if (mOps) {
138 mOps->uninitialized_move_n(new_buf, mArray, mSize);
139 mOps->destroy_n(mArray, mSize);
140 } else {
141 trivial_copy(new_buf, mArray, mSize);
142 }
143 mResource->deallocate(mArray, mCapacity * mElementSize);
144 mArray = new_buf;
146 }
147 }
148}
const vector_element_ops * mOps
bool hasInlineBuffer() const FL_NOEXCEPT
Does this vector have an inline buffer at all?
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
fl::size mInlineCapacity
void * inlineBufferPtr() FL_NOEXCEPT
Compute inline buffer pointer from offset.

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

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

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