Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] assignstrvalue() optimization
- X-seq: zsh-workers 39875
- From: Sebastian Gniazdowski <psprint@xxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [PATCH] assignstrvalue() optimization
- Date: Tue, 08 Nov 2016 08:05:05 -0800
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.com; h= content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= mesmtp; bh=lGrKz8S+sFfeacVamoKtCtMJONM=; b=OI149jGMlshMKUyXwOaD0 fJp+VvHlqTHvgS+auQ/YciWiLrm59v1InFP3OkAZtbLUBH2Zpg4dYfKxL2HJBwJe GjgEY10P2PMuAzZehbQyqerjYZzNNVVE2JBMOKxtpKXOaqn5jPM2wUUYVsM/jAbB Cqw+6siMCcW+khfaJCZ2Ns=
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=smtpout; bh=lGrKz8S+sFfeacVamoKtCtMJO NM=; b=W3+3Zd5Q7ENKBlgAnFSHTeGzXP4IJow/TJZNU11prsSZxTWB2i942oDN+ HmqQodoxFyomO56fOZ5jLRbfzCtxGqpenHLx1w49PLn/6g1VQgEodTDV8WS/JQno QRW8/86VB3ZqfuPJfGO1OvBwSXY7eFQRfdvv746yM0YENb44CE=
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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@xxxxxxxxxxxx
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:
testopt4b.zsh
Description: Binary data
Messages sorted by:
Reverse Date,
Date,
Thread,
Author