Skip to contentSkip to conversation

init: Reduce text space by removing a variable.

PATCH In review Rakib Mullick 2 participants 2 messages Jan 12, 2009 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 init: Reduce text space by removing a variable.

Impact: Reduce some text space.

We can carryout the function 'raid_setup' without the variable 'len' and using a bit compiler optimization. Which also removes 8 bytes of text space on my x86 system.

init/do_mounts_md.c +4 -4
@@ -243,17 +243,17 @@ static void __init md_setup_drive(void)
 
 static int __init raid_setup(char *str)
 {
-	int len, pos;
+	int pos;
 
-	len = strlen(str) + 1;
 	pos = 0;
 
-	while (pos < len) {
+	while (pos < strlen(str) + 1) {
 		char *comma = strchr(str+pos, ',');
 		int wlen;
 		if (comma)
 			wlen = (comma-str)-pos;
-		else	wlen = (len-1)-pos;
+		else	
+			wlen = strlen(str)-pos;
 
 		if (!strncmp(str, "noautodetect", wlen))
 			raid_noautodetect = 1;
#1 lore raw
Quoted 12 lines · Rakib Mullick

Impact: Reduce some text space.

We can carryout the function 'raid_setup' without the variable 'len' and using a bit compiler optimization. Which also removes 8 bytes of text space on my x86 system.

init/do_mounts_md.c 2009-01-12 11:12:39.734543784 +0600 renamed from init/do_mounts_md.c 2009-01-12 09:53:09.000000000 +0600 +0 -0
@@ -243,17 +243,17 @@ static void __init md_setup_drive(void)
 

init/do_mounts_md.c 2009-01-12 11:12:39.734543784 +0600 static void __init md_setup_drive(void) · line 250

Quoted 10 lines
init/do_mounts_md.c 2009-01-12 11:12:39.734543784 +0600 renamed from init/do_mounts_md.c 2009-01-12 09:53:09.000000000 +0600 +2 -3
 static int __init raid_setup(char *str)
 {
-       int len, pos;
+       int pos;
 
-       len = strlen(str) + 1;
       pos = 0;
 
-       while (pos < len) {
+       while (pos < strlen(str) + 1) {

doesn't calling strlen for every iteration (and in the else statement) add an unneeded (and unwanted) overhead?

init/do_mounts_md.c 2009-01-12 11:12:39.734543784 +0600 static void __init md_setup_drive(void)

Quoted 11 lines
init/do_mounts_md.c 2009-01-12 11:12:39.734543784 +0600 renamed from init/do_mounts_md.c 2009-01-12 09:53:09.000000000 +0600 +2 -2
               char *comma = strchr(str+pos, ',');
               int wlen;
               if (comma)
                       wlen = (comma-str)-pos;
-               else    wlen = (len-1)-pos;
+               else
+                       wlen = strlen(str)-pos;
 
               if (!strncmp(str, "noautodetect", wlen))
                       raid_noautodetect = 1;
--

Sergio.