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:
@@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user