Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] ztrsub() execution time / 2



Hello,
this optimization is a drop of callgrind instruction count by 43 mln
for ztrsub() – it had 89 mln instructions normally, now it has 46 mln:

ztrsub() callgrind I-count:
1> (89873326 - 46452836) / 1000000.0
43,4205

total callgrind I-count
2> (7906279976 - 7858975498) / 1000000.0
47,3045

 89,873,326  ztrsub [/usr/local/bin/zsh-5.6.2-dev-1-2noopt]
vs
 46,452,836  ztrsub [/usr/local/bin/zsh-5.6.2-dev-1-2yesopt]

Ran this callgrind probe twice to confirm. That said, `zsh -i -c exit'
nor a performance test script show any gain. I wonder why.. But
callgrind doesn't lie, and looking at the code one can understand why
I-count dropped by factor of 2. The patch has many context lines to
see whole function.
-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org
diff --git a/Src/utils.c b/Src/utils.c
index 914e30c..1eb8c71 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -5058,23 +5058,23 @@ ztrlenend(char const *s, char const *eptr)
 #endif /* MULTIBYTE_SUPPORT */
 
 /* Subtract two pointers in a metafied string. */
 
 /**/
 mod_export int
 ztrsub(char const *t, char const *s)
 {
     int l = t - s;
 
     while (s != t) {
-	if (*s++ == Meta) {
+	if (*s++ == Meta || (s != t && *s++ == Meta)) {
 #ifdef DEBUG
 	    if (! *s || s == t)
 		fprintf(stderr, "BUG: substring ends in the middle of a metachar in ztrsub()\n");
 	    else
 #endif
 	    s++;
 	    l--;
 	}
     }
     return l;
 }


Messages sorted by: Reverse Date, Date, Thread, Author