mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-01-01 05:16:05 +01:00
40231: Optimise setarrvalue().
This commit is contained in:
parent
d287f81340
commit
4fb4ce190c
2 changed files with 38 additions and 16 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
2016-12-28 Sebastian Gniazdowski <psprint@fastmail.com>
|
||||||
|
|
||||||
|
* 40231: Src/params.c: Optimise setarrvalue().
|
||||||
|
|
||||||
2016-12-28 Daniel Shahaf <d.s@daniel.shahaf.name>
|
2016-12-28 Daniel Shahaf <d.s@daniel.shahaf.name>
|
||||||
|
|
||||||
* 40232: configure.ac: Remove SH_USE_BSD_ECHO autoconf test.
|
* 40232: configure.ac: Remove SH_USE_BSD_ECHO autoconf test.
|
||||||
|
|
50
Src/params.c
50
Src/params.c
|
@ -2708,24 +2708,40 @@ setarrvalue(Value v, char **val)
|
||||||
post_assignment_length += pre_assignment_length - v->end;
|
post_assignment_length += pre_assignment_length - v->end;
|
||||||
}
|
}
|
||||||
|
|
||||||
p = new = (char **) zalloc(sizeof(char *)
|
if (pre_assignment_length == post_assignment_length
|
||||||
* (post_assignment_length + 1));
|
&& 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));
|
||||||
|
|
||||||
for (i = 0; i < v->start; i++)
|
for (i = 0; i < v->start; i++)
|
||||||
*p++ = i < pre_assignment_length ? ztrdup(*q++) : ztrdup("");
|
*p++ = i < pre_assignment_length ? ztrdup(*q++) : ztrdup("");
|
||||||
for (r = val; *r;) {
|
for (r = val; *r;) {
|
||||||
/* Give away ownership of the string */
|
/* Give away ownership of the string */
|
||||||
*p++ = *r++;
|
*p++ = *r++;
|
||||||
|
}
|
||||||
|
if (v->end < pre_assignment_length)
|
||||||
|
for (q = old + v->end; *q;)
|
||||||
|
*p++ = ztrdup(*q++);
|
||||||
|
*p = NULL;
|
||||||
|
|
||||||
|
DPUTS2(p - new != post_assignment_length, "setarrvalue: wrong allocation: %d 1= %lu",
|
||||||
|
post_assignment_length, (unsigned long)(p - new));
|
||||||
|
|
||||||
|
v->pm->gsu.a->setfn(v->pm, new);
|
||||||
}
|
}
|
||||||
if (v->end < pre_assignment_length)
|
|
||||||
for (q = old + v->end; *q;)
|
|
||||||
*p++ = ztrdup(*q++);
|
|
||||||
*p = NULL;
|
|
||||||
|
|
||||||
DPUTS2(p - new != post_assignment_length, "setarrvalue: wrong allocation: %d 1= %lu",
|
|
||||||
post_assignment_length, (unsigned long)(p - new));
|
|
||||||
|
|
||||||
v->pm->gsu.a->setfn(v->pm, new);
|
|
||||||
|
|
||||||
/* Ownership of all strings has been
|
/* Ownership of all strings has been
|
||||||
* given away, can plainly free */
|
* given away, can plainly free */
|
||||||
|
@ -3485,6 +3501,8 @@ arrsetfn(Param pm, char **x)
|
||||||
/* Arrays tied to colon-arrays may need to fix the environment */
|
/* Arrays tied to colon-arrays may need to fix the environment */
|
||||||
if (pm->ename && x)
|
if (pm->ename && x)
|
||||||
arrfixenv(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 */
|
/* Function to get value of an association parameter */
|
||||||
|
|
Loading…
Reference in a new issue