Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Possible huge setarrvalue optimization
- X-seq: zsh-workers 39971
- From: Sebastian Gniazdowski <psprint@xxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Possible huge setarrvalue optimization
- Date: Thu, 17 Nov 2016 22:17:09 -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=Hb8aUtM0icLtp+y1Bf3IdpuRG/E=; b=BjUu8JUgmPZz+LtfRMnrk J9F2OfONPOSndjyOR9sWe3XCmvgV84c0tEkclOv+VCtI/T2KHHvOnEXs77Om3pc2 JvWEsDFLAyvYmbtkcgGGOtJjSyMWqbAc16as/bZiPgvAD8sbF/mBQH0SU4fNTONT GSSsV86+W2G9niEUKDIYsQ=
- 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=Hb8aUtM0icLtp+y1Bf3IdpuRG /E=; b=FCbh42ZvI+SL3A68wIxKf5EJPx0VtHph09kWP9MEd0BhJOG89si4+vFaJ VRHFkqlIXe4+Jnmbb5FjIrFn9yBIY8PzPZGbm8g6dodA4gUe55rPLOSIkx+oFYgB u5KeBs06DJAfSAYHVB8GWxtZ1sldWOB3CwuBzbEWRt4N8NvQ9U=
- 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,
in params.c / setarrvalue there is code:
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);
The point is that the code is also run when doing:
a=( a b c d )
a[1]="x"
The optimization can be: no allocation of new array when size of output
array doesn't change. The problem is that following debug:
fprintf( _F, "%d %d\n", pre_assignment_length,
post_assignment_length );
Shows "4 5" for the a[1]="x" assignment. Shows the same for a+=( "x" ).
If this would be fixed, one could detect that pre_assignment_length ==
post_assignment_length, and skip allocation, only do:
for (r = val; *r;) {
/* Give away ownership of the string */
*p++ = *r++;
}
This would be a huge optimization. Has anyone idea of how the
pre_assignment_length / post_assignment_length computation works, and
why it's wrong for a[1]="x" ?
--
Sebastian Gniazdowski
psprint@xxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author