shithub: riscv

Download patch

ref: 532c7479e96e439a13df421d3b9f547cde5b5642
parent: 67eac97a81a2adf46507030a28a036ff75331f31
author: cinap_lenrek <[email protected]>
date: Wed May 12 14:04:25 EDT 2021

vmx: avoid strdup() register names for register cache

If we tokenize the register file contents in a static buffer,
we can avoid having to duplicate the register names.

All callers to rpoke() provide constant register arguments
so they also do not need to be duplicated.

--- a/sys/src/cmd/vmx/vmx.c
+++ b/sys/src/cmd/vmx/vmx.c
@@ -106,9 +106,9 @@
 }
 
 enum { RCENT = 256 };
-char *rcname[RCENT];
-uvlong rcval[RCENT];
-uvlong rcvalid[(RCENT+63)/64], rcdirty[(RCENT+63)/64];
+static char *rcname[RCENT];
+static uvlong rcval[RCENT];
+static uvlong rcvalid[(RCENT+63)/64], rcdirty[(RCENT+63)/64];
 
 static int
 rclookup(char *n)
@@ -149,7 +149,7 @@
 static void
 rcload(void)
 {
-	char buf[4096];
+	static char buf[4096];
 	char *p, *q, *f[2];
 	int nf;
 	int i, rc;
@@ -166,14 +166,12 @@
 		nf = tokenize(p, f, nelem(f));
 		p = q + 1;
 		if(nf < 2) break;
-		free(rcname[i]);
-		rcname[i] = strdup(f[0]);
+		rcname[i] = f[0];
 		rcval[i] = strtoull(f[1], nil, 0);
 		rcvalid[i>>6] |= 1ULL<<(i&63);
 	}
 	for(; i < nelem(rcname); i++){
-		free(rcname[i]);
-		rcname[i] = 0;
+		rcname[i] = nil;
 		rcvalid[i>>6] &= ~(1ULL<<(i&63));
 	}
 }
@@ -204,7 +202,7 @@
 	}
 	for(i = 0; i < nelem(rcname); i++)
 		if(rcname[i] == nil){
-			rcname[i] = strdup(reg);
+			rcname[i] = reg;
 			break;
 		}
 	assert(i < nelem(rcname));