From: André Goddard Rosa Date: Tue, 15 Dec 2009 02:01:08 +0000 (-0800) Subject: parser: remove unnecessary strlen() X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b5f54b07c06f6e438a4fee92c27423e880d8816b;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git 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 Cc: Randy Dunlap Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/lib/parser.c b/lib/parser.c index b00d02059a5f..fb34977246bb 100644 --- a/lib/parser.c +++ b/lib/parser.c @@ -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;