diff options
author | Qinfan Wu <wqfish@fb.com> | 2017-07-24 18:59:29 (GMT) |
---|---|---|
committer | Qi Wang <interwq@gmail.com> | 2017-07-24 20:37:02 (GMT) |
commit | b28f31e7ed6c987bdbf3bdd9ce4aa63245926b4d (patch) | |
tree | f0041b254ff0e651775584f32a453c705aba7f3b /src | |
parent | a9f7732d45c22ca7d22bed6ff2eaeb702356884e (diff) | |
download | jemalloc-b28f31e7ed6c987bdbf3bdd9ce4aa63245926b4d.zip jemalloc-b28f31e7ed6c987bdbf3bdd9ce4aa63245926b4d.tar.gz jemalloc-b28f31e7ed6c987bdbf3bdd9ce4aa63245926b4d.tar.bz2 |
Split out cold code path in newImpl
I noticed that the whole newImpl is inlined. Since OOM handling code is
rarely executed, we should only inline the hot path.
Diffstat (limited to 'src')
-rw-r--r-- | src/jemalloc_cpp.cpp | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/jemalloc_cpp.cpp b/src/jemalloc_cpp.cpp index 844ab39..f0cedda 100644 --- a/src/jemalloc_cpp.cpp +++ b/src/jemalloc_cpp.cpp @@ -39,12 +39,10 @@ void operator delete(void *ptr, std::size_t size) noexcept; void operator delete[](void *ptr, std::size_t size) noexcept; #endif -template <bool IsNoExcept> -void * -newImpl(std::size_t size) noexcept(IsNoExcept) { - void *ptr = je_malloc(size); - if (likely(ptr != nullptr)) - return ptr; +JEMALLOC_NOINLINE +static void * +handleOOM(std::size_t size, bool nothrow) { + void *ptr = nullptr; while (ptr == nullptr) { std::new_handler handler; @@ -68,11 +66,22 @@ newImpl(std::size_t size) noexcept(IsNoExcept) { ptr = je_malloc(size); } - if (ptr == nullptr && !IsNoExcept) + if (ptr == nullptr && !nothrow) std::__throw_bad_alloc(); return ptr; } +template <bool IsNoExcept> +JEMALLOC_ALWAYS_INLINE +void * +newImpl(std::size_t size) noexcept(IsNoExcept) { + void *ptr = je_malloc(size); + if (likely(ptr != nullptr)) + return ptr; + + return handleOOM(size, IsNoExcept); +} + void * operator new(std::size_t size) { return newImpl<false>(size); |