mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-01-19 11:31:26 +01:00
39871: cut down number of strlen()s in getstrvalue()
This commit is contained in:
parent
a57977d01a
commit
06e4ec853a
3 changed files with 32 additions and 6 deletions
|
@ -1,3 +1,7 @@
|
|||
2016-11-08 Peter Stephenson <p.stephenson@samsung.com>
|
||||
|
||||
* Sebastian: 39871: cut down number of strlen()s in getstrvalue().
|
||||
|
||||
2016-11-08 Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>
|
||||
|
||||
* 39857: Completion/Unix/Command/_top: add support for darwin,
|
||||
|
@ -5,8 +9,8 @@
|
|||
|
||||
2016-11-08 Peter Stephenson <p.stephenson@samsung.com>
|
||||
|
||||
* Src/builtin.c, Test/C03traps.ztst: ensure exit trap can always
|
||||
run.
|
||||
* 39870: Src/builtin.c, Test/C03traps.ztst: ensure exit trap can
|
||||
always run.
|
||||
|
||||
* unposted: Src/utils.c: follow up to 39867: don't need test
|
||||
against zero any more.
|
||||
|
|
17
Src/params.c
17
Src/params.c
|
@ -2060,6 +2060,7 @@ getstrvalue(Value v)
|
|||
{
|
||||
char *s, **ss;
|
||||
char buf[BDIGBUFSIZE];
|
||||
int len = -1;
|
||||
|
||||
if (!v)
|
||||
return hcalloc(1);
|
||||
|
@ -2237,22 +2238,30 @@ getstrvalue(Value v)
|
|||
return s;
|
||||
|
||||
if (v->start < 0) {
|
||||
v->start += strlen(s);
|
||||
len = strlen(s);
|
||||
v->start += len;
|
||||
if (v->start < 0)
|
||||
v->start = 0;
|
||||
}
|
||||
if (v->end < 0) {
|
||||
v->end += strlen(s);
|
||||
if (len < 0)
|
||||
len = strlen(s);
|
||||
v->end += len;
|
||||
if (v->end >= 0) {
|
||||
char *eptr = s + v->end;
|
||||
if (*eptr)
|
||||
v->end += MB_METACHARLEN(eptr);
|
||||
}
|
||||
}
|
||||
s = (v->start > (int)strlen(s)) ? dupstring("") : dupstring(s + v->start);
|
||||
|
||||
if (len < 0)
|
||||
len = strlen(s);
|
||||
s = (v->start > len) ? dupstring("") :
|
||||
dupstring_wlen(s + v->start, len - v->start);
|
||||
|
||||
if (v->end <= v->start)
|
||||
s[0] = '\0';
|
||||
else if (v->end - v->start <= (int)strlen(s))
|
||||
else if (v->end - v->start <= len - v->start)
|
||||
s[v->end - v->start] = '\0';
|
||||
|
||||
return s;
|
||||
|
|
13
Src/string.c
13
Src/string.c
|
@ -41,6 +41,19 @@ dupstring(const char *s)
|
|||
return t;
|
||||
}
|
||||
|
||||
/**/
|
||||
mod_export char *
|
||||
dupstring_wlen(const char *s, unsigned len)
|
||||
{
|
||||
char *t;
|
||||
|
||||
if (!s)
|
||||
return NULL;
|
||||
t = (char *) zhalloc(len + 1);
|
||||
strcpy(t, s);
|
||||
return t;
|
||||
}
|
||||
|
||||
/**/
|
||||
mod_export char *
|
||||
ztrdup(const char *s)
|
||||
|
|
Loading…
Reference in a new issue