From: Ivan Maidanski Date: Fri, 20 Apr 2012 04:53:46 +0000 (+0400) Subject: Code refactoring of GC_generic_malloc_inner (eliminate recursion) X-Git-Tag: gc7_3alpha2~15 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=490bf2992e2d2a0b115bb53f15aaab592f02ef8b;p=gc Code refactoring of GC_generic_malloc_inner (eliminate recursion) * malloc.c (GC_generic_malloc_inner): Update "lg" value after GC_init and GC_extend_size_map calls; add assertion on "lg" value after GC_extend_size_map call; update "opp" and "op" values and retry allocation instead of recursive call; replace "goto" with return (remove "out" label). --- diff --git a/malloc.c b/malloc.c index c9b9eb6a..0fc28fd1 100644 --- a/malloc.c +++ b/malloc.c @@ -111,16 +111,28 @@ GC_INNER void * GC_generic_malloc_inner(size_t lb, int k) op = *opp; if (EXPECT(0 == op, FALSE)) { - if (GC_size_map[lb] == 0) { - if (!EXPECT(GC_is_initialized, TRUE)) GC_init(); - if (GC_size_map[lb] == 0) GC_extend_size_map(lb); - return(GC_generic_malloc_inner(lb, k)); + if (lg == 0) { + if (!EXPECT(GC_is_initialized, TRUE)) { + GC_init(); + lg = GC_size_map[lb]; } - if (kind -> ok_reclaim_list == 0) { - if (!GC_alloc_reclaim_list(kind)) goto out; + if (0 == lg) { + GC_extend_size_map(lb); + lg = GC_size_map[lb]; + GC_ASSERT(lg != 0); } + /* Retry */ + opp = &(kind -> ok_freelist[lg]); + op = *opp; + } + if (0 == op) { + if (0 == kind -> ok_reclaim_list && + !GC_alloc_reclaim_list(kind)) + return NULL; op = GC_allocobj(lg, k); - if (op == 0) goto out; + if (0 == op) + return NULL; + } } *opp = obj_link(op); obj_link(op) = 0; @@ -130,7 +142,6 @@ GC_INNER void * GC_generic_malloc_inner(size_t lb, int k) GC_bytes_allocd += lb; } -out: return op; }