diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-04-06 06:57:20 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-04-06 06:58:10 +0400 |
commit | 43a201662a931a16027d4a088b675246df03c330 (patch) | |
tree | dfec647d0eddcd0353c4b681729913434d1bc5b3 /intern | |
parent | 1bd3922b3aa46ac06339c4306043b691cdcf6aae (diff) |
Guarded Alloc: use UNLIKELY for debug memset
Diffstat (limited to 'intern')
-rw-r--r-- | intern/guardedalloc/intern/mallocn_guarded_impl.c | 14 | ||||
-rw-r--r-- | intern/guardedalloc/intern/mallocn_lockfree_impl.c | 16 |
2 files changed, 23 insertions, 7 deletions
diff --git a/intern/guardedalloc/intern/mallocn_guarded_impl.c b/intern/guardedalloc/intern/mallocn_guarded_impl.c index 724e7f95845..d86adcf2a7c 100644 --- a/intern/guardedalloc/intern/mallocn_guarded_impl.c +++ b/intern/guardedalloc/intern/mallocn_guarded_impl.c @@ -222,6 +222,14 @@ static bool malloc_debug_memset = false; /* --------------------------------------------------------------------- */ #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 + +#ifdef __GNUC__ __attribute__ ((format(printf, 1, 2))) #endif static void print_error(const char *str, ...) @@ -497,9 +505,9 @@ void *MEM_guarded_mallocN(size_t len, const char *str) memh = (MemHead *)malloc(len + sizeof(MemHead) + sizeof(MemTail)); - if (memh) { + if (LIKELY(memh)) { make_memhead_header(memh, len, str); - if (malloc_debug_memset && len) + if (UNLIKELY(malloc_debug_memset && len)) memset(memh + 1, 255, len); #ifdef DEBUG_MEMCOUNTER @@ -951,7 +959,7 @@ static void rem_memblock(MemHead *memh) #endif } else { - if (malloc_debug_memset && memh->len) + if (UNLIKELY(malloc_debug_memset && memh->len)) memset(memh + 1, 255, memh->len); free(memh); } diff --git a/intern/guardedalloc/intern/mallocn_lockfree_impl.c b/intern/guardedalloc/intern/mallocn_lockfree_impl.c index 1d131ed339a..ccda439e29a 100644 --- a/intern/guardedalloc/intern/mallocn_lockfree_impl.c +++ b/intern/guardedalloc/intern/mallocn_lockfree_impl.c @@ -64,6 +64,14 @@ static void (*thread_unlock_callback)(void) = NULL; #define MEMHEAD_IS_MMAP(memhead) ((memhead)->len & (size_t) 1) #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 + +#ifdef __GNUC__ __attribute__ ((format(printf, 1, 2))) #endif static void print_error(const char *str, ...) @@ -126,7 +134,7 @@ void MEM_lockfree_freeN(void *vmemh) #endif } else { - if (malloc_debug_memset && len) { + if (UNLIKELY(malloc_debug_memset && len)) { memset(memh + 1, 255, len); } free(memh); @@ -219,7 +227,7 @@ void *MEM_lockfree_callocN(size_t len, const char *str) memh = (MemHead *)calloc(1, len + sizeof(MemHead)); - if (memh) { + if (LIKELY(memh)) { memh->len = len; atomic_add_u(&totblock, 1); atomic_add_z(&mem_in_use, len); @@ -242,8 +250,8 @@ void *MEM_lockfree_mallocN(size_t len, const char *str) memh = (MemHead *)malloc(len + sizeof(MemHead)); - if (memh) { - if (malloc_debug_memset && len) { + if (LIKELY(memh)) { + if (UNLIKELY(malloc_debug_memset && len)) { memset(memh + 1, 255, len); } |