1
0
Fork 0
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:
Sebastian Gniazdowski 2016-12-28 05:29:50 +00:00 committed by Daniel Shahaf
parent d287f81340
commit 4fb4ce190c
2 changed files with 38 additions and 16 deletions

View file

@ -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>
* 40232: configure.ac: Remove SH_USE_BSD_ECHO autoconf test.

View file

@ -2708,6 +2708,21 @@ setarrvalue(Value v, char **val)
post_assignment_length += pre_assignment_length - v->end;
}
if (pre_assignment_length == post_assignment_length
&& 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));
@ -2726,6 +2741,7 @@ setarrvalue(Value v, char **val)
post_assignment_length, (unsigned long)(p - new));
v->pm->gsu.a->setfn(v->pm, new);
}
/* Ownership of all strings has been
* 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 */
if (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 */