shithub: gefs

Download patch

ref: 9e59da5b58cd2a31589ca738cb301ef7fad89937
parent: ce9628320fd8fb69a06190fa7f305175e12124e6
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Apr 18 19:42:35 EDT 2023

tree: minor stylistic cleanups

mainly, adding pointers instead of computing
offsets.

--- a/tree.c
+++ b/tree.c
@@ -97,14 +97,16 @@
 void
 getval(Blk *b, int i, Kvp *kv)
 {
+	char *p;
 	int o;
 
 	assert(i >= 0 && i < b->nval);
-	o = UNPACK16(b->data + 2*i);
-	kv->nk = UNPACK16(b->data + o);
-	kv->k = b->data + o + 2;
-	kv->nv = UNPACK16(kv->k + kv->nk);
-	kv->v = kv->k + kv->nk + 2;
+	p = b->data + 2*i;
+	o = UNPACK16(p);	p = b->data + o;
+	kv->nk = UNPACK16(p);	p += 2;
+	kv->k = p;		p += kv->nk;
+	kv->nv = UNPACK16(p);	p += 2;
+	kv->v = p;
 }
 
 Bptr
@@ -111,8 +113,7 @@
 getptr(Kvp *kv, int *fill)
 {
 	assert(kv->nv == Ptrsz || kv->nv == Ptrsz+2);
-	if(fill != nil)
-		*fill = UNPACK16(kv->v + Ptrsz);
+	*fill = UNPACK16(kv->v + Ptrsz);
 	return unpackbp(kv->v, kv->nv);
 }
 
@@ -188,13 +189,14 @@
 
 	assert(b->type == Tpivot);
 	assert(i >= 0 && i < b->nbuf);
-	o = UNPACK16(b->data + Pivspc + 2*i);
+	p = b->data + Pivspc + 2*i;
+	o = UNPACK16(p);
 	p = b->data + Pivspc + o;
-	m->op = *p;
-	m->nk = UNPACK16(p + 1);
-	m->k = p + 3;
-	m->nv = UNPACK16(p + 3 + m->nk);
-	m->v = p + 5 + m->nk;
+	m->op = *p;		p += 1;
+	m->nk = UNPACK16(p);	p += 2;
+	m->k = p;		p += m->nk;
+	m->nv = UNPACK16(p);	p += 2;
+	m->v = p;
 }
 
 static int
@@ -1233,7 +1235,7 @@
 			break;
 		victim(b, &path[npath]);
 		getval(b, path[npath].idx, &sep);
-		bp = getptr(&sep, nil);
+		bp = unpackbp(sep.v, sep.nv);
 		b = getblk(bp, 0);
 		if(b == nil)
 			goto Error;
@@ -1317,7 +1319,7 @@
 	for(i = 1; i < h; i++){
 		if(blksearch(p[i-1], k, r, &same) == -1)
 			break;
-		bp = getptr(r, nil);
+		bp = unpackbp(r->v, r->nv);
 		if((p[i] = getblk(bp, 0)) == nil){
 			err = Efs;
 			goto Out;
@@ -1412,7 +1414,7 @@
 					p[i].bi++;
 				}
 			}
-			bp = getptr(&v, nil);
+			bp = unpackbp(v.v, v.nv);
 			if((b = getblk(bp, 0)) == nil)
 				return Eio;
 			p[i+1].b = b;
@@ -1460,7 +1462,7 @@
 	if(p[start-1].vi < p[start-1].b->nval){
 		for(i = start; i < h; i++){
 			getval(p[i-1].b, p[i-1].vi, &kv);
-			bp = getptr(&kv, nil);
+			bp = unpackbp(kv.v, kv.nv);
 			if((p[i].b = getblk(bp, 0)) == nil)
 				return "error reading block";
 		}