MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / _rpmalloc_aligned_reallocate

Function _rpmalloc_aligned_reallocate

source/extern/rpmalloc.c:2682–2705  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2680}
2681
2682static 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////////////

Callers 2

rpaligned_reallocFunction · 0.85

Calls 4

_rpmalloc_reallocateFunction · 0.85
_rpmalloc_usable_sizeFunction · 0.85
_rpmalloc_deallocateFunction · 0.85

Tested by

no test coverage detected