summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2023-01-18 08:15:52 +0300
committerIvan Maidanski <ivmai@mail.ru>2023-01-18 09:36:53 +0300
commit08911c9f247d385a446ebff75253c407936553cd (patch)
tree23201eb3310c35d903fc4802a13a4121b289de93
parent6ed8630b91f1d21598a069db6bbb7a072bc44915 (diff)
downloadbdwgc-08911c9f247d385a446ebff75253c407936553cd.tar.gz
Remove unneeded n_blocks local variable in malloc.c and reclaim.c
(refactoring) * malloc.c (GC_alloc_large_and_clear): Remove n_blocks local variable. * malloc.c (GC_generic_malloc): Likewise. * reclaim.c [ENABLE_DISCLAIM] (GC_disclaim_and_reclaim): Replace (*proc)() to proc(). * reclaim.c [ENABLE_DISCLAIM] (GC_reclaim_block): Likewise. * reclaim.c (GC_reclaim_block): Remove blocks local variable.
-rw-r--r--malloc.c10
-rw-r--r--reclaim.c26
2 files changed, 13 insertions, 23 deletions
diff --git a/malloc.c b/malloc.c
index 8d3fae06..dc72a62d 100644
--- a/malloc.c
+++ b/malloc.c
@@ -94,10 +94,8 @@ STATIC ptr_t GC_alloc_large_and_clear(size_t lb, int k, unsigned flags)
result = GC_alloc_large(lb, k, flags);
if (result != NULL
&& (GC_debugging_started || GC_obj_kinds[k].ok_init)) {
- word n_blocks = OBJ_SZ_TO_BLOCKS(lb);
-
/* Clear the whole block, in case of GC_realloc call. */
- BZERO(result, n_blocks * HBLKSIZE);
+ BZERO(result, HBLKSIZE * OBJ_SZ_TO_BLOCKS(lb));
}
return result;
}
@@ -258,18 +256,16 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_generic_malloc(size_t lb, int k)
} else {
size_t lg;
size_t lb_rounded;
- word n_blocks;
GC_bool init;
lg = ROUNDED_UP_GRANULES(lb);
lb_rounded = GRANULES_TO_BYTES(lg);
- n_blocks = OBJ_SZ_TO_BLOCKS(lb_rounded);
init = GC_obj_kinds[k].ok_init;
LOCK();
result = (ptr_t)GC_alloc_large(lb_rounded, k, 0);
if (0 != result) {
if (GC_debugging_started) {
- BZERO(result, n_blocks * HBLKSIZE);
+ BZERO(result, HBLKSIZE * OBJ_SZ_TO_BLOCKS(lb_rounded));
} else {
# ifdef THREADS
/* Clear any memory that might be used for GC descriptors */
@@ -284,7 +280,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_generic_malloc(size_t lb, int k)
}
UNLOCK();
if (init && !GC_debugging_started && 0 != result) {
- BZERO(result, n_blocks * HBLKSIZE);
+ BZERO(result, HBLKSIZE * OBJ_SZ_TO_BLOCKS(lb_rounded));
}
}
if (EXPECT(NULL == result, FALSE)) return (*GC_get_oom_fn())(lb);
diff --git a/reclaim.c b/reclaim.c
index 201274b7..12a325ae 100644
--- a/reclaim.c
+++ b/reclaim.c
@@ -245,8 +245,8 @@ STATIC ptr_t GC_reclaim_uninit(struct hblk *hbp, hdr *hhdr, word sz,
{
word bit_no = 0;
ptr_t p, plim;
- struct obj_kind *ok = &GC_obj_kinds[hhdr->hb_obj_kind];
- int (GC_CALLBACK *disclaim)(void *) = ok->ok_disclaim_proc;
+ struct obj_kind *ok = &GC_obj_kinds[hhdr -> hb_obj_kind];
+ int (GC_CALLBACK *disclaim)(void *) = ok -> ok_disclaim_proc;
# ifndef THREADS
GC_ASSERT(sz == hhdr -> hb_sz);
@@ -257,7 +257,7 @@ STATIC ptr_t GC_reclaim_uninit(struct hblk *hbp, hdr *hhdr, word sz,
for (; (word)p <= (word)plim; bit_no += MARK_BIT_OFFSET(sz)) {
if (mark_bit_from_hdr(hhdr, bit_no)) {
p += sz;
- } else if ((*disclaim)(p)) {
+ } else if (disclaim(p)) {
set_mark_bit_from_hdr(hhdr, bit_no);
hhdr -> hb_n_marks++;
p += sz;
@@ -392,33 +392,27 @@ STATIC void GC_CALLBACK GC_reclaim_block(struct hblk *hbp,
# ifdef AO_HAVE_load
/* Atomic access is used to avoid racing with GC_realloc. */
- sz = (word)AO_load((volatile AO_t *)&hhdr->hb_sz);
+ sz = (word)AO_load((volatile AO_t *)&(hhdr -> hb_sz));
# else
/* No race as GC_realloc holds the lock while updating hb_sz. */
sz = hhdr -> hb_sz;
# endif
- if( sz > MAXOBJBYTES ) { /* 1 big object */
- if( !mark_bit_from_hdr(hhdr, 0) ) {
+ if (sz > MAXOBJBYTES) { /* 1 big object */
+ if (!mark_bit_from_hdr(hhdr, 0)) {
if (report_if_found) {
GC_add_leaked((ptr_t)hbp);
} else {
- word blocks;
-
# ifdef ENABLE_DISCLAIM
- if (EXPECT(hhdr->hb_flags & HAS_DISCLAIM, 0)) {
- if ((*ok->ok_disclaim_proc)(hbp)) {
+ if (EXPECT(hhdr -> hb_flags & HAS_DISCLAIM, 0)) {
+ if (ok -> ok_disclaim_proc(hbp)) {
/* Not disclaimed => resurrect the object. */
set_mark_bit_from_hdr(hhdr, 0);
goto in_use;
}
}
# endif
- blocks = OBJ_SZ_TO_BLOCKS(sz);
-# if defined(CPPCHECK)
- GC_noop1((word)&blocks);
-# endif
- if (blocks > 1) {
- GC_large_allocd_bytes -= blocks * HBLKSIZE;
+ if (sz > HBLKSIZE) {
+ GC_large_allocd_bytes -= HBLKSIZE * OBJ_SZ_TO_BLOCKS(sz);
}
GC_bytes_found += sz;
GC_freehblk(hbp);