зеркало из https://github.com/microsoft/snmalloc.git
Do not realloc if size is in the same sizeclass
This commit is contained in:
Родитель
85cf5dd097
Коммит
2b8b4c884f
|
@ -80,14 +80,17 @@ extern "C"
|
|||
"Calling realloc on pointer that is not to the start of an allocation");
|
||||
}
|
||||
#endif
|
||||
if (size <= SNMALLOC_NAME_MANGLE(malloc_usable_size)(ptr))
|
||||
size_t sz = SNMALLOC_NAME_MANGLE(malloc_usable_size)(ptr);
|
||||
// Keep the current allocation if the given size is in the same sizeclass.
|
||||
if (sz == sizeclass_to_size(size_to_sizeclass(size)))
|
||||
return ptr;
|
||||
|
||||
void* p = SNMALLOC_NAME_MANGLE(malloc)(size);
|
||||
if (p != nullptr)
|
||||
{
|
||||
assert(p == Alloc::external_pointer<Start>(p));
|
||||
memcpy(p, ptr, size);
|
||||
sz = (std::min)(size, sz);
|
||||
memcpy(p, ptr, sz);
|
||||
SNMALLOC_NAME_MANGLE(free)(ptr);
|
||||
}
|
||||
return p;
|
||||
|
|
Загрузка…
Ссылка в новой задаче