remove compare and branch in fast path for c++ operator delete[]
Summary: sdallocx is checking a flag that will never be set (at least in the provided C++ destructor implementation). This branch will probably only rarely be mispredicted however it removes two instructions in sdallocx and one at the callsite (to zero out flags).
This commit is contained in:
@@ -2732,7 +2732,7 @@ bool free_fastpath(void *ptr, size_t size, bool size_hint) {
|
||||
tcache_t *tcache = tsd_tcachep_get(tsd);
|
||||
|
||||
alloc_ctx_t alloc_ctx;
|
||||
/*
|
||||
/*
|
||||
* If !config_cache_oblivious, we can check PAGE alignment to
|
||||
* detect sampled objects. Otherwise addresses are
|
||||
* randomized, and we have to look it up in the rtree anyway.
|
||||
@@ -3522,6 +3522,18 @@ je_sdallocx(void *ptr, size_t size, int flags) {
|
||||
LOG("core.sdallocx.exit", "");
|
||||
}
|
||||
|
||||
void JEMALLOC_NOTHROW
|
||||
je_sdallocx_noflags(void *ptr, size_t size) {
|
||||
LOG("core.sdallocx.entry", "ptr: %p, size: %zu, flags: 0", ptr,
|
||||
size);
|
||||
|
||||
if (!free_fastpath(ptr, size, true)) {
|
||||
sdallocx_default(ptr, size, 0);
|
||||
}
|
||||
|
||||
LOG("core.sdallocx.exit", "");
|
||||
}
|
||||
|
||||
JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW
|
||||
JEMALLOC_ATTR(pure)
|
||||
je_nallocx(size_t size, int flags) {
|
||||
|
@@ -128,14 +128,14 @@ operator delete(void *ptr, std::size_t size) noexcept {
|
||||
if (unlikely(ptr == nullptr)) {
|
||||
return;
|
||||
}
|
||||
je_sdallocx(ptr, size, /*flags=*/0);
|
||||
je_sdallocx_noflags(ptr, size);
|
||||
}
|
||||
|
||||
void operator delete[](void *ptr, std::size_t size) noexcept {
|
||||
if (unlikely(ptr == nullptr)) {
|
||||
return;
|
||||
}
|
||||
je_sdallocx(ptr, size, /*flags=*/0);
|
||||
je_sdallocx_noflags(ptr, size);
|
||||
}
|
||||
|
||||
#endif // __cpp_sized_deallocation
|
||||
|
Reference in New Issue
Block a user