From 9df96874e995cf4fb74b57af0015ef2b2886214a Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 10 Nov 2020 21:21:50 -0800 Subject: [PATCH] Start arena block doubling at initial block size. If an initial block is provided, we should start our block doubling at the size of the initial block, not 128. This saves us from unnecessary overhead when we overflow the initial block. --- upb/upb.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/upb/upb.c b/upb/upb.c index 8e6ad77142..a12656973d 100644 --- a/upb/upb.c +++ b/upb/upb.c @@ -178,15 +178,14 @@ upb_arena *upb_arena_init(void *mem, size_t n, upb_alloc *alloc) { } a = UPB_PTR_AT(mem, n - sizeof(*a), upb_arena); - n -= sizeof(*a); a->head.alloc.func = &upb_arena_doalloc; a->block_alloc = alloc; a->parent = a; a->refcount = 1; - a->last_size = 128; + a->last_size = UPB_MAX(128, n); a->head.ptr = mem; - a->head.end = UPB_PTR_AT(mem, n, char); + a->head.end = UPB_PTR_AT(mem, n - sizeof(*a), char); a->freelist = NULL; a->cleanups = NULL;