| 2680 | } |
| 2681 | |
| 2682 | static void* |
| 2683 | _rpmalloc_aligned_reallocate(heap_t* heap, void* ptr, size_t alignment, size_t size, size_t oldsize, |
| 2684 | unsigned int flags) { |
| 2685 | if (alignment <= SMALL_GRANULARITY) |
| 2686 | return _rpmalloc_reallocate(heap, ptr, size, oldsize, flags); |
| 2687 | |
| 2688 | int no_alloc = !!(flags & RPMALLOC_GROW_OR_FAIL); |
| 2689 | size_t usablesize = (ptr ? _rpmalloc_usable_size(ptr) : 0); |
| 2690 | if ((usablesize >= size) && !((uintptr_t)ptr & (alignment - 1))) { |
| 2691 | if (no_alloc || (size >= (usablesize / 2))) |
| 2692 | return ptr; |
| 2693 | } |
| 2694 | // Aligned alloc marks span as having aligned blocks |
| 2695 | void* block = (!no_alloc ? _rpmalloc_aligned_allocate(heap, alignment, size) : 0); |
| 2696 | if (EXPECTED(block != 0)) { |
| 2697 | if (!(flags & RPMALLOC_NO_PRESERVE) && ptr) { |
| 2698 | if (!oldsize) |
| 2699 | oldsize = usablesize; |
| 2700 | memcpy(block, ptr, oldsize < size ? oldsize : size); |
| 2701 | } |
| 2702 | _rpmalloc_deallocate(ptr); |
| 2703 | } |
| 2704 | return block; |
| 2705 | } |
| 2706 | |
| 2707 | |
| 2708 | //////////// |
no test coverage detected