FastLED 3.10.8
Loading...
Searching...
No Matches

◆ shrink_to_fit_impl()

void fl::vector_basic::shrink_to_fit_impl ( )

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

116 {
117 if (mSize == 0) {
118 if (!isInline() && mArray) {
119 mResource->deallocate(mArray, mCapacity * mElementSize);
120 }
121 if (hasInlineBuffer()) {
124 } else {
125 mArray = nullptr;
126 mCapacity = 0;
127 }
128 return;
129 }
130
131 // If data fits in inline buffer and we're on heap, move back to inline
132 if (hasInlineBuffer() && !isInline() && mSize <= mInlineCapacity) {
133 void* inline_buf = inlineBufferPtr();
134 if (mOps) {
136 mOps->destroy_n(mArray, mSize);
137 } else {
138 trivial_copy(inline_buf, mArray, mSize);
139 }
140 mResource->deallocate(mArray, mCapacity * mElementSize);
141 mArray = inline_buf;
143 return;
144 }
145
146 // Shrink heap allocation
147 if (!isInline() && mCapacity > mSize) {
148 void* new_buf = mResource->allocate(mSize * mElementSize);
149 if (new_buf) {
150 if (mOps) {
152 mOps->destroy_n(mArray, mSize);
153 } else {
154 trivial_copy(new_buf, mArray, mSize);
155 }
156 mResource->deallocate(mArray, mCapacity * mElementSize);
157 mArray = new_buf;
159 }
160 }
161}
bool hasInlineBuffer() const FL_NO_EXCEPT
Does this vector have an inline buffer at all?
const vector_element_ops * mOps
void trivial_copy(void *dst, const void *src, fl::size count) const FL_NO_EXCEPT
void * inlineBufferPtr() FL_NO_EXCEPT
Compute inline buffer pointer from offset.
bool isInline() const FL_NO_EXCEPT
Is data currently in the inline buffer?
fl::size mElementSize
memory_resource * mResource
void uninitialized_move_n_impl(void *dst, void *src, fl::size count) const FL_NO_EXCEPT
fl::size mInlineCapacity

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

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: