From 4769b2a9fa43f493161cf00a4ed4df9ffae4b9c1 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Tue, 26 Sep 2023 21:02:11 +0200 Subject: [memory] Remove likely/unlikely duplication in mozalloc. We already have this in mozilla/Likely.h, use that instead. --- memory/mozalloc/mozalloc.cpp | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/memory/mozalloc/mozalloc.cpp b/memory/mozalloc/mozalloc.cpp index 471687dd23..c8e37934f8 100644 --- a/memory/mozalloc/mozalloc.cpp +++ b/memory/mozalloc/mozalloc.cpp @@ -64,22 +64,15 @@ extern "C" MOZ_MEMORY_API char *strndup_impl(const char *, size_t); #include +#include "mozilla/Likely.h" #include "mozilla/mozalloc.h" #include "mozilla/mozalloc_oom.h" // for mozalloc_handle_oom -#ifdef __GNUC__ -#define LIKELY(x) (__builtin_expect(!!(x), 1)) -#define UNLIKELY(x) (__builtin_expect(!!(x), 0)) -#else -#define LIKELY(x) (x) -#define UNLIKELY(x) (x) -#endif - void* moz_xmalloc(size_t size) { void* ptr = malloc_impl(size); - if (UNLIKELY(!ptr && size)) { + if (MOZ_UNLIKELY(!ptr && size)) { mozalloc_handle_oom(size); return moz_xmalloc(size); } @@ -90,7 +83,7 @@ void* moz_xcalloc(size_t nmemb, size_t size) { void* ptr = calloc_impl(nmemb, size); - if (UNLIKELY(!ptr && nmemb && size)) { + if (MOZ_UNLIKELY(!ptr && nmemb && size)) { mozalloc_handle_oom(size); return moz_xcalloc(nmemb, size); } @@ -101,7 +94,7 @@ void* moz_xrealloc(void* ptr, size_t size) { void* newptr = realloc_impl(ptr, size); - if (UNLIKELY(!newptr && size)) { + if (MOZ_UNLIKELY(!newptr && size)) { mozalloc_handle_oom(size); return moz_xrealloc(ptr, size); } @@ -112,7 +105,7 @@ char* moz_xstrdup(const char* str) { char* dup = strdup_impl(str); - if (UNLIKELY(!dup)) { + if (MOZ_UNLIKELY(!dup)) { mozalloc_handle_oom(0); return moz_xstrdup(str); } @@ -124,7 +117,7 @@ char* moz_xstrndup(const char* str, size_t strsize) { char* dup = strndup_impl(str, strsize); - if (UNLIKELY(!dup)) { + if (MOZ_UNLIKELY(!dup)) { mozalloc_handle_oom(strsize); return moz_xstrndup(str, strsize); } @@ -137,7 +130,7 @@ int moz_xposix_memalign(void **ptr, size_t alignment, size_t size) { int err = posix_memalign_impl(ptr, alignment, size); - if (UNLIKELY(err && ENOMEM == err)) { + if (MOZ_UNLIKELY(err && ENOMEM == err)) { mozalloc_handle_oom(size); return moz_xposix_memalign(ptr, alignment, size); } @@ -172,7 +165,7 @@ void* moz_xmemalign(size_t boundary, size_t size) { void* ptr = memalign_impl(boundary, size); - if (UNLIKELY(!ptr && EINVAL != errno)) { + if (MOZ_UNLIKELY(!ptr && EINVAL != errno)) { mozalloc_handle_oom(size); return moz_xmemalign(boundary, size); } @@ -186,7 +179,7 @@ void* moz_xvalloc(size_t size) { void* ptr = valloc_impl(size); - if (UNLIKELY(!ptr)) { + if (MOZ_UNLIKELY(!ptr)) { mozalloc_handle_oom(size); return moz_xvalloc(size); } -- cgit v1.2.3