From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3742 invoked by alias); 20 Nov 2016 11:49:19 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 39992 Received: (qmail 12558 invoked from network); 20 Nov 2016 11:49:19 -0000 X-Qmail-Scanner-Diagnostics: from out5-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(66.111.4.29):SA:0(-0.7/5.0):. Processed in 1.11032 secs); 20 Nov 2016 11:49:19 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) 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= X-ME-Sender: X-Sasl-enc: RdxL53fUgoEocFGrlmsmGoPlo1M82ASzmJf+JDVvjTRJ 1479642548 Date: Sun, 20 Nov 2016 11:46:48 +0000 From: Daniel Shahaf To: Sebastian Gniazdowski Cc: zsh-workers@zsh.org Subject: Re: Possible huge setarrvalue optimization Message-ID: <20161120114648.GA6953@fujitsu.shahaf.local2> References: <1479449829.1305485.791811385.14DDFE28@webmail.messagingengine.com> <1479461540.1340250.791913609.27FAD722@webmail.messagingengine.com> <1479471620.1371132.792049209.295BE093@webmail.messagingengine.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1479471620.1371132.792049209.295BE093@webmail.messagingengine.com> User-Agent: Mutt/1.5.23 (2014-03-12) 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 */