[klibc] [klibc:update-dash] dash: [BUILTIN] Small optimisation of command -pv change

klibc-bot for Herbert Xu herbert at gondor.apana.org.au
Sat Mar 28 14:48:15 PDT 2020


Commit-ID:  966eb99fcbe60e5dc65ca75a9db95ccffcd086ac
Gitweb:     http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=966eb99fcbe60e5dc65ca75a9db95ccffcd086ac
Author:     Herbert Xu <herbert at gondor.apana.org.au>
AuthorDate: Fri, 26 Sep 2014 16:47:25 +0800
Committer:  Ben Hutchings <ben at decadent.org.uk>
CommitDate: Sat, 28 Mar 2020 21:42:54 +0000

[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 at gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben at decadent.org.uk>

---
 usr/dash/exec.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/usr/dash/exec.c b/usr/dash/exec.c
index e56e3f67..ec0eadd8 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)


More information about the klibc mailing list