mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-01-01 05:16:05 +01:00
39875: add dupstring_glen to avoid redundant strlen calls
This commit is contained in:
parent
d8786da0cd
commit
49407686b4
3 changed files with 24 additions and 2 deletions
|
@ -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>
|
2016-11-09 Daniel Shahaf <d.s@daniel.shahaf.name>
|
||||||
|
|
||||||
* 39853: Completion/Unix/Command/_subversion: Accept long
|
* 39853: Completion/Unix/Command/_subversion: Accept long
|
||||||
|
|
|
@ -2432,8 +2432,8 @@ assignstrvalue(Value v, char *val, int flags)
|
||||||
char *z, *x;
|
char *z, *x;
|
||||||
int zlen;
|
int zlen;
|
||||||
|
|
||||||
z = dupstring(v->pm->gsu.s->getfn(v->pm));
|
z = dupstring_glen(v->pm->gsu.s->getfn(v->pm), (unsigned*) &zlen);
|
||||||
zlen = strlen(z);
|
|
||||||
if ((v->flags & VALFLAG_INV) && unset(KSHARRAYS))
|
if ((v->flags & VALFLAG_INV) && unset(KSHARRAYS))
|
||||||
v->start--, v->end--;
|
v->start--, v->end--;
|
||||||
if (v->start < 0) {
|
if (v->start < 0) {
|
||||||
|
|
17
Src/string.c
17
Src/string.c
|
@ -41,6 +41,8 @@ dupstring(const char *s)
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Duplicate string on heap when length is known */
|
||||||
|
|
||||||
/**/
|
/**/
|
||||||
mod_export char *
|
mod_export char *
|
||||||
dupstring_wlen(const char *s, unsigned len)
|
dupstring_wlen(const char *s, unsigned len)
|
||||||
|
@ -54,6 +56,21 @@ dupstring_wlen(const char *s, unsigned len)
|
||||||
return t;
|
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 *
|
mod_export char *
|
||||||
ztrdup(const char *s)
|
ztrdup(const char *s)
|
||||||
|
|
Loading…
Reference in a new issue