1
0
mirror of https://github.com/roytam1/UXP.git synced 2026-05-26 13:58:49 +00:00

[memory] Remove likely/unlikely duplication in mozalloc.

We already have this in mozilla/Likely.h, use that instead.
This commit is contained in:
Moonchild
2023-09-26 21:02:11 +02:00
committed by roytam1
parent e28af7d938
commit 0548a39ff3
+9 -16
View File
@@ -64,22 +64,15 @@ extern "C" MOZ_MEMORY_API char *strndup_impl(const char *, size_t);
#include <sys/types.h>
#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);
}