From 836d7a7e69011321ba75620279a31d43a05bf0d6 Mon Sep 17 00:00:00 2001 From: Qi Wang Date: Mon, 4 Nov 2019 18:24:39 -0800 Subject: [PATCH] Check for large size first in the uncommon case of malloc. Larger sizes are not that uncommon comparing to !tsd_fast. --- src/jemalloc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/jemalloc.c b/src/jemalloc.c index 10735121..239494df 100644 --- a/src/jemalloc.c +++ b/src/jemalloc.c @@ -2344,12 +2344,10 @@ je_malloc(size_t size) { } tsd_t *tsd = tsd_get(false); - if (unlikely(!tsd || !tsd_fast(tsd) || (size > SC_LOOKUP_MAXCLASS))) { + if (unlikely((size > SC_LOOKUP_MAXCLASS) || !tsd || !tsd_fast(tsd))) { return malloc_default(size); } - tcache_t *tcache = tsd_tcachep_get(tsd); - szind_t ind = sz_size2index_lookup(size); /* * The thread_allocated counter in tsd serves as a general purpose @@ -2373,6 +2371,7 @@ je_malloc(size_t size) { return malloc_default(size); } + tcache_t *tcache = tsd_tcachep_get(tsd); cache_bin_t *bin = tcache_small_bin_get(tcache, ind); bool tcache_success; void *ret = cache_bin_alloc_easy_reduced(bin, &tcache_success);