Remove code duplication in gcj_malloc and malloc_explicitly_typed
authorIvan Maidanski <ivmai@mail.ru>
Wed, 16 May 2018 08:49:33 +0000 (11:49 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 16 May 2018 08:49:33 +0000 (11:49 +0300)
(code refactoring)

* gcj_mlc.c [GC_GCJ_SUPPORT] (GC_gcj_malloc): Store
ptr_to_struct_containing_descr in a single place of code.
* typd_mlc.c (GC_malloc_explicitly_typed_ignore_off_page): Store d (to
the object) in a single place of code.

gcj_mlc.c
typd_mlc.c

index 35b3d3f..552520c 100644 (file)
--- a/gcj_mlc.c
+++ b/gcj_mlc.c
@@ -180,9 +180,7 @@ static void maybe_finalize(void)
             GC_gcjobjfreelist[lg] = (ptr_t)obj_link(op);
             GC_bytes_allocd += GRANULES_TO_BYTES((word)lg);
         }
-        *(void **)op = ptr_to_struct_containing_descr;
         GC_ASSERT(((void **)op)[1] == 0);
-        UNLOCK();
     } else {
         LOCK();
         maybe_finalize();
@@ -192,9 +190,9 @@ static void maybe_finalize(void)
             UNLOCK();
             return((*oom_fn)(lb));
         }
-        *(void **)op = ptr_to_struct_containing_descr;
-        UNLOCK();
     }
+    *(void **)op = ptr_to_struct_containing_descr;
+    UNLOCK();
     return((void *) op);
 }
 
index 7fb964a..33c6b80 100644 (file)
@@ -636,15 +636,13 @@ GC_API GC_ATTR_MALLOC void * GC_CALL
             GC_bytes_allocd += GRANULES_TO_BYTES((word)lg);
             UNLOCK();
         }
-        ((word *)op)[GRANULES_TO_WORDS(lg) - 1] = d;
-   } else {
-       op = (ptr_t)GENERAL_MALLOC_IOP(lb, GC_explicit_kind);
-       if (op != NULL) {
-         lg = BYTES_TO_GRANULES(GC_size(op));
-         ((word *)op)[GRANULES_TO_WORDS(lg) - 1] = d;
-       }
-   }
-   return op;
+    } else {
+        op = (ptr_t)GENERAL_MALLOC_IOP(lb, GC_explicit_kind);
+        if (NULL == op) return NULL;
+        lg = BYTES_TO_GRANULES(GC_size(op));
+    }
+    ((word *)op)[GRANULES_TO_WORDS(lg) - 1] = d;
+    return op;
 }
 
 GC_API GC_ATTR_MALLOC void * GC_CALL GC_calloc_explicitly_typed(size_t n,