diff options
author | Viste <viste02@gmail.com> | 2019-11-14 23:17:38 +0300 |
---|---|---|
committer | Kargatum <dowlandtop@yandex.com> | 2019-11-15 03:17:38 +0700 |
commit | 685538b01b27ba38c605448e3a0de225bed4bb29 (patch) | |
tree | 36196f0965c5fc2fccdbc45a86a8155f2c986e4d /deps/jemalloc/src/jemalloc_cpp.cpp | |
parent | fae7ae95a373530e0b206814662df557882c8f1a (diff) |
feat(Deps/Jemalloc): update Jemalloc to 5.2.1 (#2413)
Diffstat (limited to 'deps/jemalloc/src/jemalloc_cpp.cpp')
-rw-r--r-- | deps/jemalloc/src/jemalloc_cpp.cpp | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/deps/jemalloc/src/jemalloc_cpp.cpp b/deps/jemalloc/src/jemalloc_cpp.cpp index 844ab398a7..da0441a7c9 100644 --- a/deps/jemalloc/src/jemalloc_cpp.cpp +++ b/deps/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); @@ -119,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 |