From: Ivan Maidanski Date: Thu, 29 Mar 2018 08:40:44 +0000 (+0300) Subject: Update top_index entry pointer only when the entry is constructed fully X-Git-Tag: v8.0.0~265 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9c086a3a6dda33ed0f5a1e1070e6f850796f743a;p=gc Update top_index entry pointer only when the entry is constructed fully (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. --- diff --git a/headers.c b/headers.c index 16bc8b06..9177900e 100644 --- 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); }