From d77bf2ba88c289e28139ce36ac767447113ab95d Mon Sep 17 00:00:00 2001 From: "Barton E. Schaefer" Date: Sun, 11 Oct 2015 21:16:58 -0700 Subject: 36836: zhalloc() avoids re-scanning all heaps when the last known heap with free space does not have enough space This is the second of two performance optimizations for situations where all heap arenas in the list are mostly full. --- ChangeLog | 5 ++++- Src/mem.c | 12 ++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3adb1f159..421da2f6f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ 2015-10-11 Barton E. Schaefer - * 36834: Src/mem.c: freeheap preserves last allocated heap + * 36836: Src/mem.c: zhalloc() avoids re-scanning all heaps when + the last known heap with free space does not have enough space + + * 36834: Src/mem.c: freeheap() preserves last allocated heap 2015-10-11 Frank Terbeck diff --git a/Src/mem.c b/Src/mem.c index d49f685fe..191428323 100644 --- a/Src/mem.c +++ b/Src/mem.c @@ -582,10 +582,14 @@ zhalloc(size_t size) /* find a heap with enough free space */ - for (h = ((fheap && ARENA_SIZEOF(fheap) >= (size + fheap->used)) - ? fheap : heaps); - h; h = h->next) { - hp = h; + /* + * This previously assigned: + * h = ((fheap && ARENA_SIZEOF(fheap) >= (size + fheap->used)) + * ? fheap : heaps); + * but we think that nothing upstream of fheap has more free space, + * so why start over at heaps just because fheap has too little? + */ + for (h = (fheap ? fheap : heaps); h; h = h->next) { if (ARENA_SIZEOF(h) >= (n = size + h->used)) { void *ret; -- cgit 1.4.1