shithub: neoventi

Download patch

ref: a1aaaac69337a484bb66c9c5b3ffc581b1319dac
parent: 9124769c0c1e7cb18b06be4ade8aa376dd457f04
author: Noam Preil <noam@pixelhero.dev>
date: Sat Mar 23 02:42:52 EDT 2024

disk: remove needless allocation/free in the index access path

--- a/disk.c
+++ b/disk.c
@@ -72,15 +72,12 @@
 int
 vtreadlookup(u8int *score, VtAddress *addr)
 {
-	u8int *buf;
+	u8int buf[0x2000];
 	u16int entry;
 	u64int aindex;
 	u64int bucket = U32GET(score) / index.div;
 	VtISect *s_sect = &index.sects[isectforbucket(bucket)];
 	bucket -= s_sect->start;
-	buf = malloc(s_sect->blocksize);
-	if(buf == nil)
-		sysfatal("OOM, blocksize: %d", s_sect->blocksize);
 	if(pread(s_sect->fd, (char*)buf, s_sect->blocksize, s_sect->blockbase + (bucket << s_sect->blocklog)) != s_sect->blocksize)
 		sysfatal("Failed to read bucket");
 	if(s_sect->bucketmagic && U32GET(buf + 2) != s_sect->bucketmagic)
@@ -93,7 +90,6 @@
 	aindex = aindexfromaddr(addr->offset);
 	addr->s_arena = arenafromindex(aindex);
 	addr->offset -= index.amap[aindex].start;
-	free(buf);
 	return 1;
 }