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

Method insert_copy_impl

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

Source from the content-addressed store, hash-verified

236// ======= INSERT =======
237
238void vector_basic::insert_copy_impl(fl::size index, const void* element) {
239 if (index > mSize) index = mSize;
240 ensure_capacity(mSize + 1);
241 if (mSize >= mCapacity) return; // allocation failed
242
243 if (mOps) {
244 // Shift elements right, starting from the end
245 if (mSize > index) {
246 // Move-construct the last element into uninitialized space
247 mOps->move_construct(element_ptr(mSize), element_ptr(mSize - 1));
248 // Move-assign backwards for the rest
249 for (fl::size i = mSize - 1; i > index; --i) {
250 // Destroy dst, then move-construct from src
251 mOps->destroy(element_ptr(i));
252 mOps->move_construct(element_ptr(i), element_ptr(i - 1));
253 }
254 // Destroy the slot and copy-construct the new element
255 mOps->destroy(element_ptr(index));
256 }
257 mOps->copy_construct(element_ptr(index), element);
258 } else {
259 // Trivial: memmove right, then memcpy
260 if (mSize > index) {
261 trivial_move_left(element_ptr(index + 1), element_ptr(index),
262 mSize - index);
263 }
264 fl::memcpy(element_ptr(index), element, mElementSize);
265 }
266 ++mSize;
267}
268
269void vector_basic::insert_move_impl(fl::size index, void* element) {
270 if (index > mSize) index = mSize;

Callers

nothing calls this directly

Calls 2

memcpyFunction · 0.50
destroyMethod · 0.45

Tested by

no test coverage detected