summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorBarton E. Schaefer <schaefer@zsh.org>2015-10-11 21:16:58 -0700
committerBarton E. Schaefer <schaefer@zsh.org>2015-10-11 21:16:58 -0700
commitd77bf2ba88c289e28139ce36ac767447113ab95d (patch)
treef28e3022f5d5468da7754ee5cf841700da385884 /Src
parent9f8e3e82dd2c2bb98f72b6e026b72d9c47d5ad62 (diff)
downloadzsh-d77bf2ba88c289e28139ce36ac767447113ab95d.tar.gz
zsh-d77bf2ba88c289e28139ce36ac767447113ab95d.tar.xz
zsh-d77bf2ba88c289e28139ce36ac767447113ab95d.zip
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.
Diffstat (limited to 'Src')
-rw-r--r--Src/mem.c12
1 files changed, 8 insertions, 4 deletions
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;