From b1eea5371e6161df5d34a611cbb30fcc9233a0de Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Tue, 14 Feb 2012 08:26:17 +0400 Subject: [PATCH] Minor code refactoring of GC_allochblk_nth * allchblk.c (N_HBLK_FLS): Enclose in parentheses. * allchblk.c (GC_allochblk_nth): Reformat comment; move GC_install_header invocation out of conditional expression. --- allchblk.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/allchblk.c b/allchblk.c index 60740565..b902d79c 100644 --- a/allchblk.c +++ b/allchblk.c @@ -45,8 +45,8 @@ /* In between sizes map this many distinct sizes to a single */ /* bin. */ -# define N_HBLK_FLS (HUGE_THRESHOLD - UNIQUE_THRESHOLD)/FL_COMPRESSION \ - + UNIQUE_THRESHOLD +# define N_HBLK_FLS ((HUGE_THRESHOLD - UNIQUE_THRESHOLD) / FL_COMPRESSION \ + + UNIQUE_THRESHOLD) STATIC struct hblk * GC_hblkfreelist[N_HBLK_FLS+1] = { 0 }; /* List of completely empty heap blocks */ @@ -552,7 +552,7 @@ STATIC void GC_split_block(struct hblk *h, hdr *hhdr, struct hblk *n, } STATIC struct hblk * -GC_allochblk_nth(size_t sz/* bytes */, int kind, unsigned flags, int n, +GC_allochblk_nth(size_t sz /* bytes */, int kind, unsigned flags, int n, GC_bool may_split); /* @@ -582,6 +582,7 @@ GC_allochblk(size_t sz, int kind, unsigned flags/* IGNORE_OFF_PAGE or 0 */) /* Try for an exact match first. */ result = GC_allochblk_nth(sz, kind, flags, start_list, FALSE); if (0 != result) return result; + if (GC_use_entire_heap || GC_dont_gc || USED_HEAP_SIZE < GC_requested_heapsize || GC_incremental || !GC_should_collect()) { @@ -653,8 +654,8 @@ GC_allochblk_nth(size_t sz, int kind, unsigned flags, int n, if (!may_split) continue; /* If the next heap block is obviously better, go on. */ - /* This prevents us from disassembling a single large block */ - /* to get tiny blocks. */ + /* This prevents us from disassembling a single large */ + /* block to get tiny blocks. */ thishbp = hhdr -> hb_next; if (thishbp != 0) { GET_HDR(thishbp, thishdr); @@ -666,7 +667,7 @@ GC_allochblk_nth(size_t sz, int kind, unsigned flags, int n, } } } - if ( !IS_UNCOLLECTABLE(kind) && (kind != PTRFREE + if (!IS_UNCOLLECTABLE(kind) && (kind != PTRFREE || size_needed > (signed_word)MAX_BLACK_LIST_ALLOC)) { struct hblk * lasthbp = hbp; ptr_t search_end = (ptr_t)hbp + size_avail - size_needed; @@ -675,18 +676,17 @@ GC_allochblk_nth(size_t sz, int kind, unsigned flags, int n, (signed_word)HBLKSIZE : size_needed; - while ((ptr_t)lasthbp <= search_end && (thishbp = GC_is_black_listed(lasthbp, - (word)eff_size_needed)) - != 0) { + (word)eff_size_needed)) != 0) { lasthbp = thishbp; } size_avail -= (ptr_t)lasthbp - (ptr_t)hbp; thishbp = lasthbp; if (size_avail >= size_needed) { - if (thishbp != hbp && - 0 != (thishdr = GC_install_header(thishbp))) { + if (thishbp != hbp) { + thishdr = GC_install_header(thishbp); + if (0 != thishdr) { /* Make sure it's mapped before we mangle it. */ # ifdef USE_MUNMAP if (!IS_MAPPED(hhdr)) { @@ -701,6 +701,7 @@ GC_allochblk_nth(size_t sz, int kind, unsigned flags, int n, hhdr = thishdr; /* We must now allocate thishbp, since it may */ /* be on the wrong free list. */ + } } } else if (size_needed > (signed_word)BL_LIMIT && orig_avail - size_needed -- 2.40.0