mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Bug 1423461 - Use mozilla/Likely.h in mozalloc.cpp. r=njn
Back when mozalloc.cpp was written, mozilla/Likely.h didn't exist. --HG-- extra : rebase_source : da3b4c8839a97e3ac2d40da158905ac38c088683
This commit is contained in:
parent
a646756fb7
commit
33ca8ff779
@ -59,22 +59,15 @@ MOZ_MEMORY_API char *strndup_impl(const char *, size_t);
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "mozilla/Assertions.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);
|
||||
}
|
||||
@ -85,7 +78,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);
|
||||
}
|
||||
@ -96,7 +89,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);
|
||||
}
|
||||
@ -107,7 +100,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);
|
||||
}
|
||||
@ -119,7 +112,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 @@ 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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user