1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-12-29 16:25:35 +01:00

39875: add dupstring_glen to avoid redundant strlen calls

This commit is contained in:
Sebastian Gniazdowski 2016-11-08 08:05:05 -08:00 committed by Peter Stephenson
parent d8786da0cd
commit 49407686b4
3 changed files with 24 additions and 2 deletions

View file

@ -1,3 +1,8 @@
2016-11-09 Peter Stephenson <p.stephenson@samsung.com>
* Sebastian: 39875: Src/params.c, Src/string.c: add
dupstring_glen() to avoid redundant strlen() calls.
2016-11-09 Daniel Shahaf <d.s@daniel.shahaf.name>
* 39853: Completion/Unix/Command/_subversion: Accept long

View file

@ -2432,8 +2432,8 @@ assignstrvalue(Value v, char *val, int flags)
char *z, *x;
int zlen;
z = dupstring(v->pm->gsu.s->getfn(v->pm));
zlen = strlen(z);
z = dupstring_glen(v->pm->gsu.s->getfn(v->pm), (unsigned*) &zlen);
if ((v->flags & VALFLAG_INV) && unset(KSHARRAYS))
v->start--, v->end--;
if (v->start < 0) {

View file

@ -41,6 +41,8 @@ dupstring(const char *s)
return t;
}
/* Duplicate string on heap when length is known */
/**/
mod_export char *
dupstring_wlen(const char *s, unsigned len)
@ -54,6 +56,21 @@ dupstring_wlen(const char *s, unsigned len)
return t;
}
/* Duplicate string on heap, returning length of string */
/**/
mod_export char *
dupstring_glen(const char *s, unsigned *len_ret)
{
char *t;
if (!s)
return NULL;
t = (char *) zhalloc((*len_ret = strlen((char *)s)) + 1);
strcpy(t, s);
return t;
}
/**/
mod_export char *
ztrdup(const char *s)