Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Possible huge setarrvalue optimization
- X-seq: zsh-workers 40231
 
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
 
- To: Zsh hackers list <zsh-workers@xxxxxxx>
 
- Subject: Re: Possible huge setarrvalue optimization
 
- Date: Sat, 24 Dec 2016 17:19:36 +0000
 
- Cc: Sebastian Gniazdowski <psprint@xxxxxxxxxxxx>
 
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=	daniel.shahaf.name; h=cc:content-type:date:from:in-reply-to	:message-id:mime-version:references:subject:to:x-me-sender	:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=4/p99IQPImI6X/v	orlD9U0Ivjrs=; b=jZJAWH5Ur2OK6opgKtTczBaJdVOVfpEp4sqiEsExXoURlyf	vQntEHy50ZGcoJhdAG/TTFIyHXkcyL9wyO//P3BiC6KmT65UqUsVMEluUSy1mMby	iCzidLAs3mlWqg+8A28yvsjDvlzY6GESvMAxBa1s2ANd8jPxjvVue2HoG/Ls=
 
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=	messagingengine.com; h=cc:content-type:date:from:in-reply-to	:message-id:mime-version:references:subject:to:x-me-sender	:x-me-sender:x-sasl-enc:x-sasl-enc; s=smtpout; bh=4/p99IQPImI6X/	vorlD9U0Ivjrs=; b=HVBWaxtMq67+z2KFbWaCZNnDcdS/jOgL9FrYz/Ty7XDPGC	pwuV3p/1YPsjSa0LUJC37rQcU6QXhASCuN86D68JvcLvHLrUDDsYsn5wPHueNlfQ	uZ0SR/WKu/rLO3lAh/+dnMVIjv+dnJ7GTpiIQw+Gyrvzro8nksODU6fi9JT80=
 
- In-reply-to: <CAH+w=7YsEm=3WF_fs5Zyv9n+z7QOtwyOqss6Yv9Vpvtdqz_eiA@mail.gmail.com>
 
- 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
 
- References: <1479449829.1305485.791811385.14DDFE28@webmail.messagingengine.com> <1479461540.1340250.791913609.27FAD722@webmail.messagingengine.com> <1479471620.1371132.792049209.295BE093@webmail.messagingengine.com> <20161120114648.GA6953@fujitsu.shahaf.local2> <CAH+w=7YsEm=3WF_fs5Zyv9n+z7QOtwyOqss6Yv9Vpvtdqz_eiA@mail.gmail.com>
 
Bart Schaefer wrote on Sun, Nov 20, 2016 at 09:41:48 -0800:
> This and the proposed getstr optimization both make me nervous.  I know
> Sebastian is anxious to have them appear in the next release, but it feels
> and if we should have more time using them in dev branches.
I assume we can go ahead now.
Here's a revised patch based on my review upthread:
diff --git a/Src/params.c b/Src/params.c
index 82554a7..c4dad8f 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -2708,6 +2708,23 @@ setarrvalue(Value v, char **val)
 	    post_assignment_length += pre_assignment_length - v->end;
 	}
 
+	if (pre_assignment_length == post_assignment_length
+	    && v->pm->gsu.a->setfn == arrsetfn
+	    /* ... and isn't something that arrsetfn() treats specially */
+	    && 0 == (v->pm->node.flags & (PM_SPECIAL|PM_UNIQUE))
+	    && NULL == v->pm->ename)
+    {
+	/* v->start is 0-based */
+	p = old + v->start;
+	for (r = val; *r;) {
+	    /* Free previous string */
+	    zsfree(*p);
+	    /* Give away ownership of the string */
+	    *p++ = *r++;
+	}
+    }
+	else
+    {
 	p = new = (char **) zalloc(sizeof(char *)
 		                   * (post_assignment_length + 1));
 
@@ -2726,6 +2743,7 @@ setarrvalue(Value v, char **val)
 	       post_assignment_length, (unsigned long)(p - new));
 
 	v->pm->gsu.a->setfn(v->pm, new);
+    }
 
         /* Ownership of all strings has been
          * given away, can plainly free */
@@ -3485,6 +3503,8 @@ arrsetfn(Param pm, char **x)
     /* Arrays tied to colon-arrays may need to fix the environment */
     if (pm->ename && x)
 	arrfixenv(pm->ename, x);
+    /* If you extend this function, update the list of conditions in
+     * setarrvalue(). */
 }
 
 /* Function to get value of an association parameter */
If no objections, I'll reindent and push.
Cheers,
Daniel
From b4870d1cab9db235860adcadd821069b2e2162e9 Mon Sep 17 00:00:00 2001
From: Sebastian Gniazdowski <psprint@xxxxxxxxxxxx>
Date: Tue, 22 Nov 2016 09:26:46 +0000
Subject: [PATCH] AFTER RELEASE: 39996: Optimize setarrvalue().
---
 Src/params.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
diff --git a/Src/params.c b/Src/params.c
index 82554a7..c4dad8f 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -2708,6 +2708,23 @@ setarrvalue(Value v, char **val)
 	    post_assignment_length += pre_assignment_length - v->end;
 	}
 
+	if (pre_assignment_length == post_assignment_length
+	    && v->pm->gsu.a->setfn == arrsetfn
+	    /* ... and isn't something that arrsetfn() treats specially */
+	    && 0 == (v->pm->node.flags & (PM_SPECIAL|PM_UNIQUE))
+	    && NULL == v->pm->ename)
+    {
+	/* v->start is 0-based */
+	p = old + v->start;
+	for (r = val; *r;) {
+	    /* Free previous string */
+	    zsfree(*p);
+	    /* Give away ownership of the string */
+	    *p++ = *r++;
+	}
+    }
+	else
+    {
 	p = new = (char **) zalloc(sizeof(char *)
 		                   * (post_assignment_length + 1));
 
@@ -2726,6 +2743,7 @@ setarrvalue(Value v, char **val)
 	       post_assignment_length, (unsigned long)(p - new));
 
 	v->pm->gsu.a->setfn(v->pm, new);
+    }
 
         /* Ownership of all strings has been
          * given away, can plainly free */
@@ -3485,6 +3503,8 @@ arrsetfn(Param pm, char **x)
     /* Arrays tied to colon-arrays may need to fix the environment */
     if (pm->ename && x)
 	arrfixenv(pm->ename, x);
+    /* If you extend this function, update the list of conditions in
+     * setarrvalue(). */
 }
 
 /* Function to get value of an association parameter */
Messages sorted by:
Reverse Date,
Date,
Thread,
Author