MCPcopy Create free account
hub / github.com/FastLED/FastLED / shrink_to_fit_impl

Method shrink_to_fit_impl

src/fl/stl/basic_vector.cpp.hpp:103–148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101}
102
103void vector_basic::shrink_to_fit_impl() {
104 if (mSize == 0) {
105 if (!isInline() && mArray) {
106 mResource->deallocate(mArray, mCapacity * mElementSize);
107 }
108 if (hasInlineBuffer()) {
109 mArray = inlineBufferPtr();
110 mCapacity = mInlineCapacity;
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;
129 mCapacity = mInlineCapacity;
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;
145 mCapacity = mSize;
146 }
147 }
148}
149
150// ======= PUSH / POP =======
151

Callers

nothing calls this directly

Calls 2

deallocateMethod · 0.45
allocateMethod · 0.45

Tested by

no test coverage detected