diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2014-09-26 16:47:25 +0800 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2020-03-28 21:42:54 +0000 |
commit | 966eb99fcbe60e5dc65ca75a9db95ccffcd086ac (patch) | |
tree | 2aa5bd383242359c444c55c5e4e8e436e3011372 | |
parent | 7e96bd023e7a381115727e16d9e3e57e1201d412 (diff) | |
download | klibc-966eb99fcbe60e5dc65ca75a9db95ccffcd086ac.tar.gz |
[klibc] dash: [BUILTIN] Small optimisation of command -pv change
[ dash commit 29ee27dda68a63ce8b9dccdf2c86f75a4d754b5c ]
This patch moves the pathval call into the describe_command
function and also eliminates an unnecessary branch when DEBUG
is off.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
-rw-r--r-- | usr/dash/exec.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/usr/dash/exec.c b/usr/dash/exec.c index e56e3f673939f6..ec0eadd8d02775 100644 --- a/usr/dash/exec.c +++ b/usr/dash/exec.c @@ -727,7 +727,7 @@ typecmd(int argc, char **argv) int err = 0; for (i = 1; i < argc; i++) { - err |= describe_command(out1, argv[i], pathval(), 1); + err |= describe_command(out1, argv[i], NULL, 1); } return err; } @@ -743,6 +743,8 @@ describe_command(out, command, path, verbose) struct tblentry *cmdp; const struct alias *ap; + path = path ?: pathval(); + if (verbose) { outstr(command, out); } @@ -840,19 +842,19 @@ commandcmd(argc, argv) VERIFY_BRIEF = 1, VERIFY_VERBOSE = 2, } verify = 0; - const char *path = pathval(); + const char *path = NULL; while ((c = nextopt("pvV")) != '\0') if (c == 'V') verify |= VERIFY_VERBOSE; else if (c == 'v') verify |= VERIFY_BRIEF; - else if (c == 'p') - path = defpath; #ifdef DEBUG - else + else if (c != 'p') abort(); #endif + else + path = defpath; cmd = *argptr; if (verify && cmd) |