Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Possible huge setarrvalue optimization
- X-seq: zsh-workers 39975
- From: Sebastian Gniazdowski <psprint@xxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: Possible huge setarrvalue optimization
- Date: Fri, 18 Nov 2016 04:20:20 -0800
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.com; h= 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; s=mesmtp; bh=mt3HTQM8f2e4/hxj07007VCdDO o=; b=K2Uzz8JAioQ/mf8hMg4l3oNx1qNyf5ua5vb8FFKybeYNqePzPTUT2AN7ib ota1dT16MJCWzSXI8xRnKLh82Bl62g65qs83hBM6+Xhnl02/o+e0IM1OxmWvV80W t+VpU+RvXuN3cKhzRMGg5xpbGXI9kItgH4EYnsZHwMVERirWs=
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=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; s=smtpout; bh=mt 3HTQM8f2e4/hxj07007VCdDOo=; b=fxU6pcRi4DSQElG/wRoBEvzLitNQv+cJT6 DirrG6Fh3GFVlj7f93f15XspvxHJ9jc0JeMg31qqJjR1ID0XBi4O1RLp9ASsRvgN 8ZaMqh5pkbvv93ydBMI1qjGgZ1cqPTcYCUINII+6cPWcm/8+SCGnrECk1USX+pJu OW9ix1NHU=
- In-reply-to: <1479461540.1340250.791913609.27FAD722@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>
OK, the patch should now be complete. There is condition whether to use
all-duplicate code path:
if (pre_assignment_length != post_assignment_length ||
v->pm->node.flags & (PM_SPECIAL|PM_UNIQUE)) {
This covers special arrays and uniq arrays, that should be always
calling setfn() to trigger side-effects. Other arrays use this code:
/* 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++;
}
And it should be OK, zsfree() for non-special array should be always
successful.
--
Sebastian Gniazdowski
psprint@xxxxxxxxxxxx
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;
-
- 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);
+ if (v->end <= pre_assignment_length)
+ post_assignment_length += pre_assignment_length - v->end;
+
+ if (pre_assignment_length != post_assignment_length || v->pm->node.flags & (PM_SPECIAL|PM_UNIQUE)) {
+ 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++;
+ }
+ }
/* Ownership of all strings has been
* given away, can plainly free */
Messages sorted by:
Reverse Date,
Date,
Thread,
Author