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

Method reallocate_impl

src/fl/stl/allocator.h:182–204  ·  view source on GitHub ↗

SFINAE: Use fl::realloc() for trivially copyable types

Source from the content-addressed store, hash-verified

180private:
181 // SFINAE: Use fl::realloc() for trivially copyable types
182 pointer reallocate_impl(pointer ptr, fl::size old_count, fl::size new_count, fl::true_type) FL_NOEXCEPT {
183 if (new_count == 0) {
184 if (ptr) {
185 deallocate(ptr, old_count);
186 }
187 return nullptr;
188 }
189
190 // Safe to use realloc() - type is trivially copyable
191 void* result = fl::realloc(ptr, new_count * sizeof(T));
192 if (!result) {
193 return nullptr; // Realloc failed
194 }
195
196 T* new_ptr = static_cast<T*>(result);
197
198 // Zero-initialize any newly allocated memory
199 if (new_count > old_count) {
200 fl::memset(new_ptr + old_count, 0, (new_count - old_count) * sizeof(T));
201 }
202
203 return new_ptr;
204 }
205
206 // SFINAE: Don't use realloc() for non-trivially-copyable types
207 pointer reallocate_impl(pointer ptr, fl::size old_count, fl::size new_count, fl::false_type) FL_NOEXCEPT {

Callers

nothing calls this directly

Calls 3

deallocateFunction · 0.85
memsetFunction · 0.85
reallocFunction · 0.70

Tested by

no test coverage detected