Rewrite iteration through applet names to save a few bytes
authorRon Yorston <rmy@pobox.com>
Fri, 8 Apr 2016 10:57:20 +0000 (11:57 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Fri, 15 Apr 2016 20:13:51 +0000 (22:13 +0200)
function                                             old     new   delta
run_applet_and_exit                                  758     755      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-3)               Total: -3 bytes

In standalone shell mode the saving increases to 17 bytes.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
libbb/appletlib.c
libbb/lineedit.c
shell/ash.c

index de654f64c8b34086ed0d7ea57dda3e3195c0650b..b682e6b8592bbff0ecbe9bc6096aa8b4d8a9f687 100644 (file)
@@ -791,7 +791,8 @@ static int busybox_main(char **argv)
                        full_write2_str(a);
                        full_write2_str("\n");
                        i++;
-                       a += strlen(a) + 1;
+                       while (*a++ != '\0')
+                               continue;
                }
                return 0;
        }
index 2ddb2b6e9632342ecfddd0952f2b605acec8f4f9..3e62f46b4cf548833db2e7df2def3f05aa3af984 100644 (file)
@@ -779,12 +779,11 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type)
        if (type == FIND_EXE_ONLY) {
                const char *p = applet_names;
 
-               i = 0;
-               while (i < NUM_APPLETS) {
+               while (*p) {
                        if (strncmp(pfind, p, pf_len) == 0)
                                add_match(xstrdup(p));
-                       p += strlen(p) + 1;
-                       i++;
+                       while (*p++ != '\0')
+                               continue;
                }
        }
 #endif
index 5613e1f336cebfb8af7259053bf0c3397745a9e2..13eeab34b2e2ef15aeab9cf548d5f58c292016d9 100644 (file)
@@ -12597,7 +12597,8 @@ helpcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
                                out1fmt("\n");
                                col = 0;
                        }
-                       a += strlen(a) + 1;
+                       while (*a++ != '\0')
+                               continue;
                }
        }
 # endif