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 be97d4924192f4758d3b2884547a12ed91e16d43..78cf235dd006cae01c326006d69e2d79e24f3e18 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);