OPTIMIZED: reallocate() - in-place resize using fl::realloc() Returns the new pointer if successful, nullptr if not supported/failed The caller (fl::vector) handles fallback to allocate-copy-deallocate
| 360 | // Returns the new pointer if successful, nullptr if not supported/failed |
| 361 | // The caller (fl::vector) handles fallback to allocate-copy-deallocate |
| 362 | pointer reallocate(pointer ptr, fl::size old_count, fl::size new_count) FL_NOEXCEPT { |
| 363 | if (new_count == 0) { |
| 364 | if (ptr) { |
| 365 | deallocate(ptr, old_count); |
| 366 | } |
| 367 | return nullptr; |
| 368 | } |
| 369 | |
| 370 | // Use fl::realloc() for in-place resize |
| 371 | void* result = fl::realloc(ptr, new_count * sizeof(T)); |
| 372 | if (!result) { |
| 373 | return nullptr; // Realloc failed |
| 374 | } |
| 375 | |
| 376 | T* new_ptr = static_cast<T*>(result); |
| 377 | |
| 378 | // Zero-initialize any newly allocated memory |
| 379 | if (new_count > old_count) { |
| 380 | fl::memset(new_ptr + old_count, 0, (new_count - old_count) * sizeof(T)); |
| 381 | } |
| 382 | |
| 383 | return new_ptr; |
| 384 | } |
| 385 | }; |
| 386 | |
| 387 | template <typename T> class allocator_psram { |
nothing calls this directly
no test coverage detected