From bd42ffaecd040791c2c0d83e2aa920760e8b02e2 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Sun, 14 Jun 2015 23:18:36 +0900 Subject: [PATCH] with fixed sized chunk heaps, grow a new heap for the chunk size when applicable --- gc.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/gc.c b/gc.c index f1b9387b..43a675c6 100644 --- a/gc.c +++ b/gc.c @@ -525,10 +525,20 @@ sexp_heap sexp_make_heap (size_t size, size_t max_size, size_t chunk_size) { int sexp_grow_heap (sexp ctx, size_t size, size_t chunk_size) { size_t cur_size, new_size; - sexp_heap h = sexp_heap_last(sexp_context_heap(ctx)); + sexp_heap tmp, h = sexp_heap_last(sexp_context_heap(ctx)); +#if SEXP_USE_FIXED_CHUNK_SIZE_HEAPS + for (tmp=sexp_context_heap(ctx); tmp; tmp=tmp->next) + if (tmp->chunk_size == size) { + h = tmp; + chunk_size = size; + break; + } +#endif cur_size = h->size; new_size = sexp_heap_align(((cur_size > size) ? cur_size : size) * 2); - h->next = sexp_make_heap(new_size, h->max_size, chunk_size); + tmp = sexp_make_heap(new_size, h->max_size, chunk_size); + tmp->next = h->next; + h->next = tmp; return (h->next != NULL); }