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:
Schrodinger ZHU Yifan
2021-11-18 00:05:52 +08:00
committed by GitHub
parent cd0311b26f
commit faa80037bb
11 changed files with 36 additions and 33 deletions

View File

@@ -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;

View File

@@ -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;
}