summaryrefslogtreecommitdiffstats
path: root/bin/sh/parser.c
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2010-11-23 22:17:39 +0000
committerjilles <jilles@FreeBSD.org>2010-11-23 22:17:39 +0000
commit7377de8f916e2389e9f1c47ca8f7de558aaca6ef (patch)
treeff9e8102b66741a601dc54d4455bad759b583a8b /bin/sh/parser.c
parent77837b201a907898ee7c79f6a8584102187a089a (diff)
downloadFreeBSD-src-7377de8f916e2389e9f1c47ca8f7de558aaca6ef.zip
FreeBSD-src-7377de8f916e2389e9f1c47ca8f7de558aaca6ef.tar.gz
sh: Code size optimizations to "stack string" memory allocation:
* Prefer one CHECKSTRSPACE with multiple USTPUTC to multiple STPUTC. * Add STPUTS macro (based on function) and use it instead of loops that add nul-terminated strings to the stack string. No functional change is intended, but code size is about 1K less on i386.
Diffstat (limited to 'bin/sh/parser.c')
-rw-r--r--bin/sh/parser.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/bin/sh/parser.c b/bin/sh/parser.c
index 01907e8..2687003 100644
--- a/bin/sh/parser.c
+++ b/bin/sh/parser.c
@@ -1017,6 +1017,7 @@ parsebackq(char *out, struct nodelist **pbqlist,
setprompt(2);
needprompt = 0;
}
+ CHECKSTRSPACE(2, oout);
switch (c = pgetc()) {
case '`':
goto done;
@@ -1031,14 +1032,14 @@ parsebackq(char *out, struct nodelist **pbqlist,
/*
* If eating a newline, avoid putting
* the newline into the new character
- * stream (via the STPUTC after the
+ * stream (via the USTPUTC after the
* switch).
*/
continue;
}
if (c != '\\' && c != '`' && c != '$'
&& (!dblquote || c != '"'))
- STPUTC('\\', oout);
+ USTPUTC('\\', oout);
break;
case '\n':
@@ -1054,10 +1055,10 @@ parsebackq(char *out, struct nodelist **pbqlist,
default:
break;
}
- STPUTC(c, oout);
+ USTPUTC(c, oout);
}
done:
- STPUTC('\0', oout);
+ USTPUTC('\0', oout);
olen = oout - stackblock();
INTOFF;
ostr = ckmalloc(olen);
@@ -1444,7 +1445,6 @@ parsesub: {
char *p;
static const char types[] = "}-+?=";
int bracketed_name = 0; /* used to handle ${[0-9]*} variables */
- int i;
int linno;
int length;
@@ -1498,8 +1498,7 @@ parsesub: {
linno -= funclinno - 1;
snprintf(buf, sizeof(buf), "%d", linno);
STADJUST(-6, out);
- for (i = 0; buf[i] != '\0'; i++)
- STPUTC(buf[i], out);
+ STPUTS(buf, out);
flags |= VSLINENO;
}
} else if (is_digit(c)) {
OpenPOWER on IntegriCloud