diff mbox series

[2/3] parser: Merge first and last chkeofmark branches in parsesub

Message ID 6687ab4e862db7a356c9fa11d019f29a46f97fda.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
Elminate the first chkeofmark branch by moving the CTLVAR to the
end of the parsesub block and always doing STADJUST.

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

Patch

diff --git a/src/parser.c b/src/parser.c
index b711d6c..2517721 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1293,10 +1293,9 @@  parseredir: {
  */
 
 parsesub: {
-	int subtype;
-	int typeloc;
-	char *p;
 	static const char types[] = "}-+?=";
+	int subtype;
+	char *p;
 
 	USTPUTC('$', out);
 
@@ -1310,13 +1309,10 @@  parsesub: {
 			PARSEBACKQNEW();
 		}
 	} else if (c == '{' || is_name(c) || is_special(c)) {
+		int typeloc = out - (char *)stackblock();
 		const char *newsyn = synstack->syntax;
 
-		typeloc = out - (char *)stackblock();
-		if (!chkeofmark) {
-			out[-1] = CTLVAR;
-			STADJUST(1, out);
-		}
+		STADJUST(!chkeofmark, out);
 		subtype = VSNORMAL;
 		if (likely(c == '{')) {
 			if (chkeofmark)
@@ -1432,7 +1428,10 @@  badsub:
 				synstack->dqvarnest++;
 		}
 		if (!chkeofmark) {
-			*((char *)stackblock() + typeloc) = subtype | VSBIT;
+			char *p = stackblock();
+
+			p[typeloc - 1] = CTLVAR;
+			p[typeloc] = subtype | VSBIT;
 			STPUTC('=', out);
 		}
 	} else