* [PATCH] assignstrvalue() optimization
@ 2016-11-08 16:05 Sebastian Gniazdowski
0 siblings, 0 replies; only message in thread
From: Sebastian Gniazdowski @ 2016-11-08 16:05 UTC (permalink / raw)
To: zsh-workers
[-- Attachment #1: Type: text/plain, Size: 483 bytes --]
Hello,
patch is very simple – utilizes dupstring's internal strlen to not call
strlen again outside. Following test function:
strtest() {
a=""
i=$(( 20000 ))
while (( i -- )); do
a+="aaaaaaaaaaaaaaaaaaaaaaaaa"
done
}
runs for 1511 ms with optimizations, 1829 ms with no optimizations.
Changing to i=$(( 10000 )) gives times 364 ms 414 ms, 50 ms difference
(minimum obtainable times).
--
Sebastian Gniazdowski
psprint@fastmail.com
[-- Attachment #2: string_opt2.diff --]
[-- Type: text/plain, Size: 932 bytes --]
diff --git a/Src/params.c b/Src/params.c
index 5005042..5fab84a 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -2428,8 +2428,8 @@ assignstrvalue(Value v, char *val, int flags)
char *z, *x;
int zlen;
- z = dupstring(v->pm->gsu.s->getfn(v->pm));
- zlen = strlen(z);
+ z = dupstring_glen(v->pm->gsu.s->getfn(v->pm), (unsigned*) &zlen);
+
if ((v->flags & VALFLAG_INV) && unset(KSHARRAYS))
v->start--, v->end--;
if (v->start < 0) {
diff --git a/Src/string.c b/Src/string.c
index b46ea60..ce0cf51 100644
--- a/Src/string.c
+++ b/Src/string.c
@@ -56,6 +56,19 @@ dupstring_wlen(const char *s, unsigned len)
/**/
mod_export char *
+dupstring_glen(const char *s, unsigned *len_ret)
+{
+ char *t;
+
+ if (!s)
+ return NULL;
+ t = (char *) zhalloc((*len_ret = strlen((char *)s)) + 1);
+ strcpy(t, s);
+ return t;
+}
+
+/**/
+mod_export char *
ztrdup(const char *s)
{
char *t;
[-- Attachment #3: testopt4b.zsh --]
[-- Type: application/octet-stream, Size: 203 bytes --]
#!Src/zsh-opt4
#!Src/zsh-opt4-before
zmodload zsh/zprof
strtest() {
a=""
i=$(( 20000 ))
while (( i -- )); do
a+="aaaaaaaaaaaaaaaaaaaaaaaaa"
done
}
strtest
zprof | head -n 25
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2016-11-08 16:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-08 16:05 [PATCH] assignstrvalue() optimization Sebastian Gniazdowski
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).