parser: remove unnecessary strlen()

No functional change.  Cache strlen() result to avoid recalculating it up
to 3 times on the worst case.

Reduces code size a little by 32 bytes:
   text    data     bss     dec     hex filename
   1385       0       0    1385     569 lib/parser.o-BEFORE
   1353       0       0    1353     549 lib/parser.o-AFTER

Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>
Cc: Randy Dunlap <randy.dunlap@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
André Goddard Rosa 2009-12-14 18:01:08 -08:00 committed by Linus Torvalds
parent e7d2860b69
commit b5f54b07c0

View file

@ -56,13 +56,16 @@ static int match_one(char *s, const char *p, substring_t args[])
args[argc].from = s; args[argc].from = s;
switch (*p++) { switch (*p++) {
case 's': case 's': {
if (strlen(s) == 0) size_t str_len = strlen(s);
if (str_len == 0)
return 0; return 0;
else if (len == -1 || len > strlen(s)) if (len == -1 || len > str_len)
len = strlen(s); len = str_len;
args[argc].to = s + len; args[argc].to = s + len;
break; break;
}
case 'd': case 'd':
simple_strtol(s, &args[argc].to, 0); simple_strtol(s, &args[argc].to, 0);
goto num; goto num;