summary refs log tree commit diff
diff options
context:
space:
mode:
authorSebastian Gniazdowski <psprint@zdharma.org>2017-07-05 09:35:57 +0200
committerPeter Stephenson <p.w.stephenson@ntlworld.com>2017-07-09 17:34:55 +0100
commite556f9c78d0216c2a543035586bc3a7cd1918d73 (patch)
tree26d0d6af666caebd68dee51d1ae53727b2185f13
parenta955065cda3dcaa80058520ba55dc0bf5c8d3f08 (diff)
downloadzsh-e556f9c78d0216c2a543035586bc3a7cd1918d73.tar.gz
zsh-e556f9c78d0216c2a543035586bc3a7cd1918d73.tar.xz
zsh-e556f9c78d0216c2a543035586bc3a7cd1918d73.zip
41402: Add hasher to ecstrcode to reduce string comparisons
-rw-r--r--ChangeLog5
-rw-r--r--Src/parse.c6
-rw-r--r--Src/zsh.h1
3 files changed, 11 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index d5ff3f5e7..b3e702cd1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2017-07-09  Peter Stephenson  <p.w.stephenson@ntlworld.com>
+
+	* Sebastian: 41402: Src/parse.c, Src/zsh.h: Add hasher to
+	ecstrcode() to reduce string comparisons.
+
 2017-07-04  Peter Stephenson  <p.stephenson@samsung.com>
 
 	* 41391: Doc/Zsh/jobs.yo, Src/jobs.c, Src/zsh.h: delay disown
diff --git a/Src/parse.c b/Src/parse.c
index 8769baae4..00a8f6a5a 100644
--- a/Src/parse.c
+++ b/Src/parse.c
@@ -396,6 +396,8 @@ ecstrcode(char *s)
 {
     int l, t = has_token(s);
 
+    unsigned val = hasher(s);
+
     if ((l = strlen(s) + 1) && l <= 4) {
 	wordcode c = (t ? 3 : 2);
 	switch (l) {
@@ -410,8 +412,9 @@ ecstrcode(char *s)
 	int cmp;
 
 	for (pp = &ecstrs; (p = *pp); ) {
-	    if (!(cmp = p->nfunc - ecnfunc) && !(cmp = strcmp(p->str, s)))
+	    if (!(cmp = p->nfunc - ecnfunc) && !(cmp = (((signed)p->hashval) - ((signed)val))) && !(cmp = strcmp(p->str, s))) {
 		return p->offs;
+            }
 	    pp = (cmp < 0 ? &(p->left) : &(p->right));
 	}
 	p = *pp = (Eccstr) zhalloc(sizeof(*p));
@@ -420,6 +423,7 @@ ecstrcode(char *s)
 	p->aoffs = ecsoffs;
 	p->str = s;
 	p->nfunc = ecnfunc;
+        p->hashval = val;
 	ecsoffs += l;
 
 	return p->offs;
diff --git a/Src/zsh.h b/Src/zsh.h
index a5b4d8fc4..ccd11db3d 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -813,6 +813,7 @@ struct eccstr {
     char *str;
     wordcode offs, aoffs;
     int nfunc;
+    int hashval;
 };
 
 #define EC_NODUP  0