mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] parser: remove unnecessary strlen()
@ 2009-11-18 16:02 André Goddard Rosa
  0 siblings, 0 replies; only message in thread
From: André Goddard Rosa @ 2009-11-18 16:02 UTC (permalink / raw)
  To: linux-kernel; +Cc: André Goddard Rosa

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>
---
 lib/parser.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/lib/parser.c b/lib/parser.c
index b00d020..fb34977 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;
-- 
1.6.5.3.148.g785c5


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-11-19 16:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-18 16:02 [PATCH] parser: remove unnecessary strlen() André Goddard Rosa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®