mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-06-30 03:06:03 +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
|
|
@ -1100,22 +1100,18 @@ JEMALLOC_ATTR(visibility("default"))
|
|||
void
|
||||
je_free(void *ptr)
|
||||
{
|
||||
size_t usize;
|
||||
|
||||
if (ptr != NULL) {
|
||||
size_t usize;
|
||||
assert(malloc_initialized || IS_INITIALIZER);
|
||||
|
||||
assert(malloc_initialized || IS_INITIALIZER);
|
||||
|
||||
if (config_prof && opt_prof) {
|
||||
usize = isalloc(ptr);
|
||||
prof_free(ptr, usize);
|
||||
} else if (config_stats) {
|
||||
usize = isalloc(ptr);
|
||||
}
|
||||
if (config_stats)
|
||||
thread_allocated_tsd_get()->deallocated += usize;
|
||||
idalloc(ptr);
|
||||
}
|
||||
if (config_prof && opt_prof) {
|
||||
usize = isalloc(ptr);
|
||||
prof_free(ptr, usize);
|
||||
} else if (config_stats)
|
||||
usize = isalloc(ptr);
|
||||
if (config_stats)
|
||||
thread_allocated_tsd_get()->deallocated += usize;
|
||||
idalloc(ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -1200,7 +1196,7 @@ je_malloc_usable_size(const void *ptr)
|
|||
if (config_ivsalloc)
|
||||
ret = ivsalloc(ptr);
|
||||
else
|
||||
ret = (ptr != NULL) ? isalloc(ptr) : 0;
|
||||
ret = isalloc(ptr);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue