shithub: git9

Download patch

ref: 43b4a73ee9c12c10d1ce50a1bb17c567b2fd7508
parent: 01ec593ff86964cd4b002f557f12dedb60a844d1
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Jan 17 21:21:09 EST 2021

pack: make LRU cache work when fully drained.

The added checks are only needed when the LRU
cache is fully drained, which should never be
the case: it should grow to the expected size,
and then stay roughly steady.

However, a reader would need to convince
themselves of this when inspecting the code,
so this removes a few questions.

--- a/pack.c
+++ b/pack.c
@@ -140,7 +140,8 @@
 		o->next->prev = o->prev;
 	if(lrutail == o){
 		lrutail = o->prev;
-		lrutail->next = nil;
+		if(lrutail != nil)
+			lrutail->next = nil;
 	}else if(lrutail == nil)
 		lrutail = o;
 	if(lruhead)
@@ -154,10 +155,11 @@
 		ref(o);
 		ncache++;
 	}
-	while(ncache > cachemax){
+	while(ncache > cachemax && lrutail != nil){
 		p = lrutail;
 		lrutail = p->prev;
-		lrutail->next = nil;
+		if(lrutail != nil)
+			lrutail->next = nil;
 		p->flag &= ~Ccache;
 		p->prev = nil;
 		p->next = nil;