Skip to content

Commit

Permalink
parser: remove unnecessary strlen()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Randy Dunlap <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
andre-rosa authored and torvalds committed Dec 15, 2009
1 parent e7d2860 commit b5f54b0
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,16 @@ static int match_one(char *s, const char *p, substring_t args[])

args[argc].from = s;
switch (*p++) {
case 's':
if (strlen(s) == 0)
case 's': {
size_t str_len = strlen(s);

if (str_len == 0)
return 0;
else if (len == -1 || len > strlen(s))
len = strlen(s);
if (len == -1 || len > str_len)
len = str_len;
args[argc].to = s + len;
break;
}
case 'd':
simple_strtol(s, &args[argc].to, 0);
goto num;
Expand Down

0 comments on commit b5f54b0

Please sign in to comment.