summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2014-09-26 16:47:25 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2014-09-26 16:47:25 +0800
commit29ee27dda68a63ce8b9dccdf2c86f75a4d754b5c (patch)
treec8485a8d81c2377759ac176e5b645c4407c03c5b /src
parent[BUILTIN] command: allow combining -p with -v (diff)
downloaddash-29ee27dda68a63ce8b9dccdf2c86f75a4d754b5c.tar.gz
dash-29ee27dda68a63ce8b9dccdf2c86f75a4d754b5c.zip
[BUILTIN] Small optimisation of command -pv change
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>
Diffstat (limited to '')
-rw-r--r--src/exec.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/exec.c b/src/exec.c
index e56e3f6..ec0eadd 100644
--- a/src/exec.c
+++ b/src/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)