alloc-util: use malloc_usable_size() to determine allocated size
It's a glibc-specific API, but supported on FreeBSD and musl too at least, hence fairly common. This way we can reduce our calls to realloc() as much as possible.
This commit is contained in:
parent
23964f7faf
commit
d4b604baea
|
@ -1,5 +1,6 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include <malloc.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
|
@ -64,7 +65,7 @@ void* greedy_realloc(void **p, size_t *allocated, size_t need, size_t size) {
|
|||
return NULL;
|
||||
|
||||
*p = q;
|
||||
*allocated = newalloc;
|
||||
*allocated = _unlikely_(size == 0) ? newalloc : malloc_usable_size(q) / size;
|
||||
return q;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue