diff options
author | jackpoz <giacomopoz@gmail.com> | 2018-05-11 20:36:14 +0200 |
---|---|---|
committer | jackpoz <giacomopoz@gmail.com> | 2018-05-12 09:37:51 +0200 |
commit | 8fe74bf0f90aab0b23d5ff21079cba4201bb4fdf (patch) | |
tree | dbd187bf59f55f81cb81d01acd4998077553fb9b /dep/jemalloc/src/jemalloc_cpp.cpp | |
parent | e5b3814020fe1a288f4cd8bbf0289bd0abfd5c10 (diff) |
Dep/Jemalloc: Update to Jemalloc 5.1.0
Diffstat (limited to 'dep/jemalloc/src/jemalloc_cpp.cpp')
-rw-r--r-- | dep/jemalloc/src/jemalloc_cpp.cpp | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/dep/jemalloc/src/jemalloc_cpp.cpp b/dep/jemalloc/src/jemalloc_cpp.cpp index 844ab398a71..f0ceddae33a 100644 --- a/dep/jemalloc/src/jemalloc_cpp.cpp +++ b/dep/jemalloc/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); |