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

Method trivial_swap

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

Source from the content-addressed store, hash-verified

26}
27
28void vector_basic::trivial_swap(void* a, void* b) const {
29 // Stack buffer for small elements, heap for large
30 char stack_buf[64];
31 void* tmp;
32 bool heap_allocated = false;
33 if (mElementSize <= sizeof(stack_buf)) {
34 tmp = stack_buf;
35 } else {
36 tmp = mResource->allocate(mElementSize);
37 heap_allocated = true;
38 }
39 fl::memcpy(tmp, a, mElementSize);
40 fl::memcpy(a, b, mElementSize);
41 fl::memcpy(b, tmp, mElementSize);
42 if (heap_allocated) {
43 mResource->deallocate(tmp, mElementSize);
44 }
45}
46
47// ======= CAPACITY / GROWTH =======
48

Callers

nothing calls this directly

Calls 3

memcpyFunction · 0.50
allocateMethod · 0.45
deallocateMethod · 0.45

Tested by

no test coverage detected