mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-02 11:57:17 +03:00
Avoid NULL check in free() and malloc_usable_size().
Generalize isalloc() to handle NULL pointers in such a way that the NULL checking overhead is only paid when introspecting huge allocations (or NULL). This allows free() and malloc_usable_size() to no longer check for NULL. Submitted by Igor Bukanov and Mike Hommey.
This commit is contained in:
parent
80b25932ca
commit
96d4120ac0
5 changed files with 37 additions and 22 deletions
|
|
@ -633,8 +633,6 @@ isalloc(const void *ptr)
|
|||
size_t ret;
|
||||
arena_chunk_t *chunk;
|
||||
|
||||
assert(ptr != NULL);
|
||||
|
||||
chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
|
||||
if (chunk != ptr) {
|
||||
/* Region. */
|
||||
|
|
@ -642,8 +640,10 @@ isalloc(const void *ptr)
|
|||
ret = arena_salloc_demote(ptr);
|
||||
else
|
||||
ret = arena_salloc(ptr);
|
||||
} else
|
||||
} else if (ptr != NULL)
|
||||
ret = huge_salloc(ptr);
|
||||
else
|
||||
ret = 0;
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
|
@ -664,12 +664,10 @@ idalloc(void *ptr)
|
|||
{
|
||||
arena_chunk_t *chunk;
|
||||
|
||||
assert(ptr != NULL);
|
||||
|
||||
chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
|
||||
if (chunk != ptr)
|
||||
arena_dalloc(chunk->arena, chunk, ptr);
|
||||
else
|
||||
else if (ptr != NULL)
|
||||
huge_dalloc(ptr, true);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue