]> granicus.if.org Git - gc/commitdiff
Update top_index entry pointer only when the entry is constructed fully
authorIvan Maidanski <ivmai@mail.ru>
Thu, 29 Mar 2018 08:40:44 +0000 (11:40 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 29 Mar 2018 08:40:44 +0000 (11:40 +0300)
(code refactoring)

* headers.c [HASH_TL] (get_index): Remove old local variable (use pi
instead).
* headers.c (get_index): Eliminate code duplication; use EXPECT() to
check the result of GC_scratch_alloc().
* headers.c (get_index): Update GC_top_index[i] value only at the end
of the function.

headers.c

index 16bc8b0627e4e34db46ff46badc10921442474a8..9177900e735a52c41f7f0597c0b3c4592d935065 100644 (file)
--- a/headers.c
+++ b/headers.c
@@ -205,7 +205,7 @@ GC_INNER void GC_init_headers(void)
     }
 }
 
-/* Make sure that there is a bottom level index block for address addr  */
+/* Make sure that there is a bottom level index block for address addr. */
 /* Return FALSE on failure.                                             */
 static GC_bool get_index(word addr)
 {
@@ -213,30 +213,31 @@ static GC_bool get_index(word addr)
     bottom_index * r;
     bottom_index * p;
     bottom_index ** prev;
-    bottom_index *pi;
+    bottom_index *pi; /* old_p */
+    word i;
 
 #   ifdef HASH_TL
-      word i = TL_HASH(hi);
-      bottom_index * old;
+      i = TL_HASH(hi);
 
-      old = p = GC_top_index[i];
+      pi = p = GC_top_index[i];
       while(p != GC_all_nils) {
           if (p -> key == hi) return(TRUE);
           p = p -> hash_link;
       }
-      r = (bottom_index *)GC_scratch_alloc(sizeof(bottom_index));
-      if (r == 0) return(FALSE);
-      BZERO(r, sizeof (bottom_index));
-      r -> hash_link = old;
-      GC_top_index[i] = r;
 #   else
-      if (GC_top_index[hi] != GC_all_nils) return(TRUE);
-      r = (bottom_index *)GC_scratch_alloc(sizeof(bottom_index));
-      if (r == 0) return(FALSE);
-      GC_top_index[hi] = r;
-      BZERO(r, sizeof (bottom_index));
+      if (GC_top_index[hi] != GC_all_nils)
+        return TRUE;
+      i = hi;
 #   endif
+    r = (bottom_index *)GC_scratch_alloc(sizeof(bottom_index));
+    if (EXPECT(NULL == r, FALSE))
+      return FALSE;
+    BZERO(r, sizeof(bottom_index));
     r -> key = hi;
+#   ifdef HASH_TL
+      r -> hash_link = pi;
+#   endif
+
     /* Add it to the list of bottom indices */
       prev = &GC_all_bottom_indices;    /* pointer to p */
       pi = 0;                           /* bottom_index preceding p */
@@ -252,6 +253,8 @@ static GC_bool get_index(word addr)
       }
       r -> asc_link = p;
       *prev = r;
+
+      GC_top_index[i] = r;
     return(TRUE);
 }