zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] ztrsub() execution time / 2
@ 2018-10-17  4:29 Sebastian Gniazdowski
  2018-10-17 14:25 ` Daniel Shahaf
  0 siblings, 1 reply; 4+ messages in thread
From: Sebastian Gniazdowski @ 2018-10-17  4:29 UTC (permalink / raw)
  To: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 893 bytes --]

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

[-- Attachment #2: ztrsub_opt.diff.txt --]
[-- Type: text/plain, Size: 633 bytes --]

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;
 }

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-10-17 19:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-17  4:29 [PATCH] ztrsub() execution time / 2 Sebastian Gniazdowski
2018-10-17 14:25 ` Daniel Shahaf
2018-10-17 19:02   ` Sebastian Gniazdowski
2018-10-17 19:34     ` Daniel Shahaf

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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).