9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] git: speed up commit parsing
@ 2021-09-04 22:53 ori
  0 siblings, 0 replies; only message in thread
From: ori @ 2021-09-04 22:53 UTC (permalink / raw)
  To: 9front

regexec() was at the top of the profile, so I
removed it. This costs a few extra lines of
code, but the parsing isn't too complicated.

This cuts down the amount of time in finding
hairy least-common-ancestors by about 20%,
and moves the bottleneck to decompression.

---
diff e5c05ed4491bb5df233d15bf5b2334c806f21e2e 2ac33147fcdfac36c2c8c40da73b5e9cbc929353
--- a/sys/src/cmd/git/git.h	Sat Sep  4 17:58:31 2021
+++ b/sys/src/cmd/git/git.h	Sat Sep  4 18:32:20 2021
@@ -2,7 +2,6 @@
 #include <mp.h>
 #include <libsec.h>
 #include <flate.h>
-#include <regexp.h>
 
 typedef struct Conn	Conn;
 typedef struct Hash	Hash;
@@ -247,7 +246,6 @@
 #define isblank(c) \
 	(((c) != '\n') && isspace(c))
 
-extern Reprog	*authorpat;
 extern Objset	objcache;
 extern Hash	Zhash;
 extern int	chattygit;
--- a/sys/src/cmd/git/pack.c	Sat Sep  4 17:58:31 2021
+++ b/sys/src/cmd/git/pack.c	Sat Sep  4 18:32:20 2021
@@ -809,32 +809,33 @@
 static int
 parseauthor(char **str, int *nstr, char **name, vlong *time)
 {
-	char buf[128];
-	Resub m[4];
-	char *p;
-	int n, nm;
+	char *s, *p;
+	int i, tz;
 
 	if((p = strchr(*str, '\n')) == nil)
 		sysfatal("malformed author line");
-	n = p - *str;
-	if(n >= sizeof(buf))
-		sysfatal("overlong author line");
-	memset(m, 0, sizeof(m));
-	snprint(buf, n + 1, *str);
+	s = *str;
+	i = p - s;
 	*str = p;
-	*nstr -= n;
-	
-	if(!regexec(authorpat, buf, m, nelem(m)))
-		sysfatal("invalid author line %s", buf);
-	nm = m[1].ep - m[1].sp;
-	*name = emalloc(nm + 1);
-	memcpy(*name, m[1].sp, nm);
-	buf[nm] = 0;
+	*nstr -= i;
+
+	while(i > 0 && (s[i-1] == ' ' || s[i-1] == '\t'))
+		i--;
+	while(i > 0 && (s[i-1] != ' ' && s[i-1] != '\t'))
+		i--;
+	tz = atoi(s+i);
+
+	while(i > 0 && (s[i-1] == ' ' || s[i-1] == '\t'))
+		i--;
+	while(i > 0 && (s[i-1] != ' ' && s[i-1] != '\t'))
+		i--;
+	*time = atoll(s+i) + (tz/100)*3600 + (tz%100)*60;
+
+	while(i > 0 && (s[i-1] == ' ' || s[i-1] == '\t'))
+		i--;
+	*name = emalloc(i+1);
+	strecpy(*name, *name+i, s);
 	
-	nm = m[2].ep - m[2].sp;
-	memcpy(buf, m[2].sp, nm);
-	buf[nm] = 0;
-	*time = atoll(buf);
 	return 0;
 }
 
--- a/sys/src/cmd/git/util.c	Sat Sep  4 17:58:31 2021
+++ b/sys/src/cmd/git/util.c	Sat Sep  4 18:32:20 2021
@@ -4,7 +4,6 @@
 
 #include "git.h"
 
-Reprog *authorpat;
 Hash Zhash;
 
 int chattygit;
@@ -201,7 +200,6 @@
 	fmtinstall('Q', Qfmt);
 	inflateinit();
 	deflateinit();
-	authorpat = regcomp("[\t ]*(.*)[\t ]+([0-9]+)[\t ]+([\\-+]?[0-9]+)");
 	osinit(&objcache);
 }
 


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-09-04 22:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-04 22:53 [9front] git: speed up commit parsing ori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).