From: Eric Andersen Date: Wed, 4 Apr 2001 22:49:01 +0000 (-0000) Subject: Patch from Larry Doolittle to eliminate needless thrashing X-Git-Tag: 0_51~45 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=3c0364f3911ec9f43e1c8c96ec2c8e30b1b52c47;p=oweals%2Fbusybox.git Patch from Larry Doolittle to eliminate needless thrashing about when trimming long strings with lots of trailing white space. --- diff --git a/libbb/trim.c b/libbb/trim.c index be97d4924..78cf235dd 100644 --- a/libbb/trim.c +++ b/libbb/trim.c @@ -33,11 +33,11 @@ void trim(char *s) { - int len; + int len=strlen(s); /* trim trailing whitespace */ - while ( (len=strlen(s)) >= 1 && isspace(s[len-1])) - s[len-1]='\0'; + while ( len > 0 && isspace(s[len-1])) + s[--len]='\0'; /* trim leading whitespace */ memmove(s, &s[strspn(s, " \n\r\t\v")], len);