git: 9front

Download patch

ref: f3ac883d0db6842870cdabd44ed938b92de87d71
parent: e16f6004ab0807ecce5aa9d894a854a136947349
author: qwx <qwx@sciops.net>
date: Mon Oct 27 01:34:36 EDT 2025

split: give up on looking up names to avoid strdup

the first arg may be a tempcell with no name; with additional
checks this is getting unwieldy just to avoid a strdup.

--- a/sys/src/cmd/awk/run.c
+++ b/sys/src/cmd/awk/run.c
@@ -1267,8 +1267,9 @@
 	int n, nb, sep, arg3type;
 
 	y = execute(a[0]);	/* source string */
-	ds = nil;
-	s = getsval(y);
+	ds = s = tostring(getsval(y));
+	if (istemp(y))
+		tfree(y);
 	arg3type = ptoi(a[3]);
 	if (a[2] == 0)		/* fs string */
 		fs = *FS;
@@ -1281,8 +1282,6 @@
 		FATAL("illegal type of split");
 	sep = *fs;
 	ap = execute(a[1]);	/* array name */
-	if (isarr(ap) && lookup(y->nval, (Array *)ap->sval) != nil)
-		ds = s = tostring(s);
 	freesymtab(ap);
 	   dprint( ("split: s=|%s|, a=%s, sep=|%s|\n", s, ap->nval, fs) );
 	ap->tval &= ~STR;
@@ -1385,8 +1384,6 @@
 	free(ds);
 	if (istemp(ap))
 		tfree(ap);
-	if (istemp(y))
-		tfree(y);
 	if (a[2] != 0 && arg3type == STRING)
 		if (istemp(x))
 			tfree(x);
--