objformat: Avoid unnecessary getenv calls
authorJohn Marino <draco@marino.st>
Sun, 12 Feb 2012 11:13:28 +0000 (12:13 +0100)
committerJohn Marino <draco@marino.st>
Sun, 12 Feb 2012 11:48:25 +0000 (12:48 +0100)
The CCVER and BINUTILSVERS are always checked by objformat, even when
these values won't be used.  For example, there's no need to know the
value of CCVER when executing the realelf binutils binary, but it was
getting requested in all cases.

This commit limits the getenv requests to the bare minimum required.
Additionally it adds whitespace to the commands structure for the
purpose of aesthetics.

usr.bin/objformat/objformat.c

index ed0d2de..d46d0ce 100644 (file)
@@ -59,31 +59,31 @@ struct command {
 };
 
 static struct command commands[] = {
-       {"CC",          COMPILER},
-       {"c++",         COMPILER},
-       {"cc",          COMPILER},
-       {"cpp",         COMPILER},
-       {"g++",         COMPILER},
-       {"gcc",         COMPILER},
-       {"gcov",        COMPILER},
-       {"ld",          LINKER},
-       {"addr2line",   BINUTILS},
-       {"ar",          BINUTILS},
-       {"as",          BINUTILS},
-       {"c++filt",     BINUTILS},
-       {"elfedit",     BINUTILS},
-       {"gprof",       BINUTILS},
-       {"nm",          BINUTILS},
-       {"objcopy",     BINUTILS},
-       {"objdump",     BINUTILS},
-       {"ranlib",      BINUTILS},
-       {"readelf",     BINUTILS},
-       {"size",        BINUTILS},
-       {"strings",     BINUTILS},
-       {"strip",       BINUTILS},
-       {"incremental-dump", BINUTILS},
-       {"objformat",   OBJFORMAT},
-       {"",            -1}
+       {"CC",                  COMPILER},
+       {"c++",                 COMPILER},
+       {"cc",                  COMPILER},
+       {"cpp",                 COMPILER},
+       {"g++",                 COMPILER},
+       {"gcc",                 COMPILER},
+       {"gcov",                COMPILER},
+       {"ld",                  LINKER},
+       {"addr2line",           BINUTILS},
+       {"ar",                  BINUTILS},
+       {"as",                  BINUTILS},
+       {"c++filt",             BINUTILS},
+       {"elfedit",             BINUTILS},
+       {"gprof",               BINUTILS},
+       {"nm",                  BINUTILS},
+       {"objcopy",             BINUTILS},
+       {"objdump",             BINUTILS},
+       {"ranlib",              BINUTILS},
+       {"readelf",             BINUTILS},
+       {"size",                BINUTILS},
+       {"strings",             BINUTILS},
+       {"strip",               BINUTILS},
+       {"incremental-dump",    BINUTILS},
+       {"objformat",           OBJFORMAT},
+       {"",                    -1}
 };
 
 int
@@ -121,24 +121,28 @@ main(int argc, char **argv)
                        break;
        }
 
-       if ((ccver = getenv("CCVER")) == NULL || ccver[0] == 0)
-               ccver = CCVER_DEFAULT;
-       if ((buver = getenv("BINUTILSVER")) == NULL)
-               buver = BINUTILSVER_DEFAULT;
-
        if (cmds) {
                switch (cmds->type) {
                case COMPILER:
+                       ccver = getenv("CCVER");
+                       if ((ccver == NULL) || ccver[0] == 0)
+                           ccver = CCVER_DEFAULT;
                        base_path = "/usr/libexec";
                        use_objformat = 0;
                        env_value = ccver;
                        break;
                case BINUTILS:
+                       buver = getenv("BINUTILSVER");
+                       if (buver == NULL)
+                           buver = BINUTILSVER_DEFAULT;
                        base_path = "/usr/libexec";
                        use_objformat = 1;
                        env_value = buver;
                        break;
                case LINKER:
+                       buver = getenv("BINUTILSVER");
+                       if (buver == NULL)
+                           buver = BINUTILSVER_DEFAULT;
                        ldver = getenv("LINKERVER");
                        if ((ldver != NULL) && (strcmp(ldver, ld_gold) == 0))
                            ldcmd = ld_gold;