]> granicus.if.org Git - gc/commitdiff
Code refactoring of GC_generic_malloc_inner (eliminate recursion)
authorIvan Maidanski <ivmai@mail.ru>
Fri, 20 Apr 2012 04:53:46 +0000 (08:53 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 20 Apr 2012 11:55:58 +0000 (15:55 +0400)
* 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).

malloc.c

index c9b9eb6a8a7e22bf5606d1753bf658e3d53513a5..0fc28fd1c532ae88f4a7babca77b10f3a7558abc 100644 (file)
--- 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;
 }