Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] ztrsub() execution time / 2
- X-seq: zsh-workers 43700
- From: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: [PATCH] ztrsub() execution time / 2
- Date: Wed, 17 Oct 2018 06:29:08 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=siTMTxb16pbPelYUcKWwLuvS9NG2Zrzsih6X2L0+YHg=; b=bZA76d98I20Hgo5GdFkMVO6lovsQ/F1dQJ76FH95/zmpE/feyo7uT1Qynjz0m13YoI U0h58880GS0aycqdjLDW5yHOwHtavPTfSkBZoMo1JPoXooTjKyjO8CEVoqe/kZj0esz1 l549ASdlOjLEl+zunxsul+Up8SYcNqWNtHe4eALXg0DDikRNr1Dpqh1ZnQPL9HenDOXg kT5Ebj8uxHKeaQd0hPUACI5A5eEI6q0sFktb70kMMoLGzpjvalpASlJFapZ2PWtRyzIA HEHyzssS9FBkHojLtT8kmUWn2mPYgGp5hgS1sgA/0AQ2jeQxhN6a8tBfQkRbil0Oqra/ Duig==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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