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.
This commit is contained in:
parent
a9f7732d45
commit
b28f31e7ed
@ -39,12 +39,10 @@ void operator delete(void *ptr, std::size_t size) noexcept;
|
|||||||
void operator delete[](void *ptr, std::size_t size) noexcept;
|
void operator delete[](void *ptr, std::size_t size) noexcept;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template <bool IsNoExcept>
|
JEMALLOC_NOINLINE
|
||||||
void *
|
static void *
|
||||||
newImpl(std::size_t size) noexcept(IsNoExcept) {
|
handleOOM(std::size_t size, bool nothrow) {
|
||||||
void *ptr = je_malloc(size);
|
void *ptr = nullptr;
|
||||||
if (likely(ptr != nullptr))
|
|
||||||
return ptr;
|
|
||||||
|
|
||||||
while (ptr == nullptr) {
|
while (ptr == nullptr) {
|
||||||
std::new_handler handler;
|
std::new_handler handler;
|
||||||
@ -68,11 +66,22 @@ newImpl(std::size_t size) noexcept(IsNoExcept) {
|
|||||||
ptr = je_malloc(size);
|
ptr = je_malloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ptr == nullptr && !IsNoExcept)
|
if (ptr == nullptr && !nothrow)
|
||||||
std::__throw_bad_alloc();
|
std::__throw_bad_alloc();
|
||||||
return ptr;
|
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 *
|
void *
|
||||||
operator new(std::size_t size) {
|
operator new(std::size_t size) {
|
||||||
return newImpl<false>(size);
|
return newImpl<false>(size);
|
||||||
|
Loading…
Reference in New Issue
Block a user