diff mbox series

[1/3] parser: Move non-variable case in parsesub to end

Message ID 99d0bd52d6f2c402b074c8ae995dfb2c8faeceea.1718001832.git.herbert@gondor.apana.org.au (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show
Series Add dollar single quote | expand

Commit Message

Herbert Xu June 10, 2024, 6:45 a.m. UTC
Move the rare case of a literal dollar sign to the end of the
parsesub block.  This eliminates a duplicate USTPUTC call.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---
 src/parser.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/src/parser.c b/src/parser.c
index 3d21894..b711d6c 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1298,15 +1298,9 @@  parsesub: {
 	char *p;
 	static const char types[] = "}-+?=";
 
-	c = pgetc_eatbnl();
-	if (c != '(' && c != '{' && !is_name(c) && !is_special(c)) {
-		USTPUTC('$', out);
-		pungetc();
-		goto parsesub_return;
-	}
-
 	USTPUTC('$', out);
 
+	c = pgetc_eatbnl();
 	if (c == '(') {		/* $(command) or $((arith)) */
 		USTPUTC(c, out);
 		if (pgetc_eatbnl() == '(') {
@@ -1315,7 +1309,7 @@  parsesub: {
 			pungetc();
 			PARSEBACKQNEW();
 		}
-	} else {
+	} else if (c == '{' || is_name(c) || is_special(c)) {
 		const char *newsyn = synstack->syntax;
 
 		typeloc = out - (char *)stackblock();
@@ -1441,7 +1435,9 @@  badsub:
 			*((char *)stackblock() + typeloc) = subtype | VSBIT;
 			STPUTC('=', out);
 		}
-	}
+	} else
+		pungetc();
+
 	goto parsesub_return;
 }