Patch from Larry Doolittle to eliminate needless thrashing
authorEric Andersen <andersen@codepoet.org>
Wed, 4 Apr 2001 22:49:01 +0000 (22:49 -0000)
committerEric Andersen <andersen@codepoet.org>
Wed, 4 Apr 2001 22:49:01 +0000 (22:49 -0000)
about when trimming long strings with lots of trailing white
space.

libbb/trim.c

index be97d49..78cf235 100644 (file)
 
 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);