Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Possible huge setarrvalue optimization
- X-seq: zsh-workers 39992
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Sebastian Gniazdowski <psprint@xxxxxxxxxxxx>
- Subject: Re: Possible huge setarrvalue optimization
- Date: Sun, 20 Nov 2016 11:46:48 +0000
- Cc: zsh-workers@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=cc:content-transfer-encoding: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=T/9hxuhuhMUJFSue8PMkku2zYDw=; b=SAihPHUlc9cKXR2ehOn95 4x5BoP3S1C3xV9h+yaRurhZdFkS2nNTtJdq9TYkn0e6FQ1w3M6ICtdaRgo9qhTZs M9Rpfk2X6/AP/pCt90jvVruIsyQUh2mf87oj5J0EXgH6y+6jnEbaIl7sl0Yx+++K XfLitgn5eXPU6p89hX4TiE=
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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=T/9hxuhuhMUJFSue8PMkku2zYDw=; b=LWa4AQOebDSzPFhC6uVK wc71OJ9tbFQ00QyRCrctCTBD53oTeJxpXp2VpwNxcliOzoJgvqqJ/0KJP+nxNEEu W+4/RaVjqsj5ligu/9ARmFsqI5DHSq/hNbv9EDSlssjGNbFjapj0Tvx08MilzA+a MGDPLt1IYrRXec13IJ3eLTE=
- In-reply-to: <1479471620.1371132.792049209.295BE093@webmail.messagingengine.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>
Sebastian Gniazdowski wrote on Fri, Nov 18, 2016 at 04:20:20 -0800:
> diff --git a/Src/params.c b/Src/params.c
> index ef72cba..eac8375 100644
> --- a/Src/params.c
> +++ b/Src/params.c
> @@ -2654,24 +2654,36 @@ setarrvalue(Value v, char **val)
> v->end = v->start;
>
> post_assignment_length = v->start + arrlen(val);
> - if (v->end <= pre_assignment_length)
> - post_assignment_length += pre_assignment_length - v->end + 1;
> + if (v->end <= pre_assignment_length)
> + post_assignment_length += pre_assignment_length - v->end;
> -
I'll go ahead and commit the off-by-one fix now, since it is a bugfix
independent of the performance optimisation.
> - p = new = (char **) zshcalloc(sizeof(char *)
> - * (post_assignment_length + 1));
The calloc is no longer present in latest master, so the patch failed to
apply. (The patch did apply to 5f17007, but next time, please send
patches that apply to latest master.)
> -
> - for (i = 0; i < v->start; i++)
> - *p++ = i < pre_assignment_length ? ztrdup(*q++) : ztrdup("");
> - for (r = val; *r;) {
> - /* Give away ownership of the string */
> - *p++ = *r++;
> - }
> - if (v->end < pre_assignment_length)
> - for (q = old + v->end; *q;)
> - *p++ = ztrdup(*q++);
> - *p = NULL;
>
> - v->pm->gsu.a->setfn(v->pm, new);
> +
> + if (pre_assignment_length != post_assignment_length || v->pm->node.flags & (PM_SPECIAL|PM_UNIQUE)) {
Should this line check that «v->pm->gsu.a.setfn == arrsetfn»?
Should this line check that «pm->ename == NULL» [since arrsetfn()
handles such arrays specially]?
> + p = new = (char **) zshcalloc(sizeof(char *)
> + * (post_assignment_length + 1));
> +
> + for (i = 0; i < v->start; i++)
> + *p++ = i < pre_assignment_length ? ztrdup(*q++) : ztrdup("");
> + for (r = val; *r;) {
> + /* Give away ownership of the string */
> + *p++ = *r++;
> + }
> + if (v->end < pre_assignment_length)
> + for (q = old + v->end; *q;)
> + *p++ = ztrdup(*q++);
> + *p = NULL;
> +
> + v->pm->gsu.a->setfn(v->pm, new);
> + } else {
> + /* 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++;
> + }
Looks good. Could you rebase to latest master please?
Cheers,
Daniel
> + }
>
> /* Ownership of all strings has been
> * given away, can plainly free */
Messages sorted by:
Reverse Date,
Date,
Thread,
Author