mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-04-15 07:01:42 +03:00
Inline malloc fastpath into operator new.
This saves a small but non-negligible amount of CPU in C++ programs.
This commit is contained in:
parent
79f81a3732
commit
edbfe6912c
5 changed files with 141 additions and 119 deletions
|
|
@ -86,10 +86,10 @@ handleOOM(std::size_t size, bool nothrow) {
|
|||
}
|
||||
|
||||
template <bool IsNoExcept>
|
||||
JEMALLOC_ALWAYS_INLINE
|
||||
void *
|
||||
newImpl(std::size_t size) noexcept(IsNoExcept) {
|
||||
void *ptr = je_malloc(size);
|
||||
JEMALLOC_NOINLINE
|
||||
static void *
|
||||
fallback_impl(std::size_t size) noexcept(IsNoExcept) {
|
||||
void *ptr = malloc_default(size);
|
||||
if (likely(ptr != nullptr)) {
|
||||
return ptr;
|
||||
}
|
||||
|
|
@ -97,6 +97,13 @@ newImpl(std::size_t size) noexcept(IsNoExcept) {
|
|||
return handleOOM(size, IsNoExcept);
|
||||
}
|
||||
|
||||
template <bool IsNoExcept>
|
||||
JEMALLOC_ALWAYS_INLINE
|
||||
void *
|
||||
newImpl(std::size_t size) noexcept(IsNoExcept) {
|
||||
return imalloc_fastpath(size, &fallback_impl<IsNoExcept>);
|
||||
}
|
||||
|
||||
void *
|
||||
operator new(std::size_t size) {
|
||||
return newImpl<false>(size);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue