put likely/unlikely in scope (#420)
* put likely/unlikely in scope Signed-off-by: SchrodingerZhu <i@zhuyi.fan> * make clang-format happy Signed-off-by: SchrodingerZhu <i@zhuyi.fan>
This commit is contained in:
committed by
GitHub
parent
cd0311b26f
commit
faa80037bb
@@ -47,7 +47,7 @@ extern "C"
|
||||
{
|
||||
bool overflow = false;
|
||||
size_t sz = bits::umul(size, nmemb, overflow);
|
||||
if (unlikely(overflow))
|
||||
if (SNMALLOC_UNLIKELY(overflow))
|
||||
{
|
||||
return SNMALLOC_NAME_MANGLE(snmalloc_set_error)();
|
||||
}
|
||||
@@ -85,7 +85,7 @@ extern "C"
|
||||
}
|
||||
|
||||
void* p = a.alloc(size);
|
||||
if (likely(p != nullptr))
|
||||
if (SNMALLOC_LIKELY(p != nullptr))
|
||||
{
|
||||
sz = bits::min(size, sz);
|
||||
// Guard memcpy as GCC is assuming not nullptr for ptr after the memcpy
|
||||
@@ -94,7 +94,7 @@ extern "C"
|
||||
memcpy(p, ptr, sz);
|
||||
a.dealloc(ptr);
|
||||
}
|
||||
else if (likely(size == 0))
|
||||
else if (SNMALLOC_LIKELY(size == 0))
|
||||
{
|
||||
a.dealloc(ptr);
|
||||
}
|
||||
@@ -150,7 +150,7 @@ extern "C"
|
||||
}
|
||||
|
||||
void* p = SNMALLOC_NAME_MANGLE(memalign)(alignment, size);
|
||||
if (unlikely(p == nullptr))
|
||||
if (SNMALLOC_UNLIKELY(p == nullptr))
|
||||
{
|
||||
if (size != 0)
|
||||
return ENOMEM;
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace
|
||||
auto& alloc = ThreadAlloc::get();
|
||||
void* p = const_cast<void*>(ptr);
|
||||
|
||||
if (unlikely(alloc.remaining_bytes(ptr) < len))
|
||||
if (SNMALLOC_UNLIKELY(alloc.remaining_bytes(ptr) < len))
|
||||
{
|
||||
if constexpr (FailFast)
|
||||
{
|
||||
@@ -209,7 +209,7 @@ extern "C"
|
||||
// 0 is a very common size for memcpy and we don't need to do external
|
||||
// pointer checks if we hit it. It's also the fastest case, to encourage
|
||||
// the compiler to favour the other cases.
|
||||
if (unlikely(len == 0))
|
||||
if (SNMALLOC_UNLIKELY(len == 0))
|
||||
{
|
||||
return dst;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user