summaryrefslogtreecommitdiffstats
path: root/bin/sh/expand.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/expand.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/expand.c')
-rw-r--r--bin/sh/expand.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/bin/sh/expand.c b/bin/sh/expand.c
index d251ed0..7a3b9d9 100644
--- a/bin/sh/expand.c
+++ b/bin/sh/expand.c
@@ -225,6 +225,7 @@ argstr(char *p, int flag)
if (*p == '~' && (flag & (EXP_TILDE | EXP_VARTILDE)))
p = exptilde(p, flag);
for (;;) {
+ CHECKSTRSPACE(2, expdest);
switch (c = *p++) {
case '\0':
case CTLENDVAR:
@@ -235,16 +236,16 @@ argstr(char *p, int flag)
if (p[0] == CTLVAR && p[2] == '@' && p[3] == '=')
break;
if ((flag & EXP_FULL) != 0)
- STPUTC(c, expdest);
+ USTPUTC(c, expdest);
break;
case CTLQUOTEEND:
lit_quoted = 0;
break;
case CTLESC:
if (quotes)
- STPUTC(c, expdest);
+ USTPUTC(c, expdest);
c = *p++;
- STPUTC(c, expdest);
+ USTPUTC(c, expdest);
if (split_lit && !lit_quoted)
recordregion(expdest - stackblock() -
(quotes ? 2 : 1),
@@ -267,7 +268,7 @@ argstr(char *p, int flag)
* sort of a hack - expand tildes in variable
* assignments (after the first '=' and after ':'s).
*/
- STPUTC(c, expdest);
+ USTPUTC(c, expdest);
if (split_lit && !lit_quoted)
recordregion(expdest - stackblock() - 1,
expdest - stackblock(), 0);
@@ -279,7 +280,7 @@ argstr(char *p, int flag)
}
break;
default:
- STPUTC(c, expdest);
+ USTPUTC(c, expdest);
if (split_lit && !lit_quoted)
recordregion(expdest - stackblock() - 1,
expdest - stackblock(), 0);
@@ -902,8 +903,7 @@ varvalue(char *name, int quoted, int subtype, int flag)
STPUTC(*p++, expdest); \
} \
} else \
- while (*p) \
- STPUTC(*p++, expdest); \
+ STPUTS(p, expdest); \
} while (0)
@@ -1573,8 +1573,7 @@ cvtnum(int num, char *buf)
if (neg)
*--p = '-';
- while (*p)
- STPUTC(*p++, buf);
+ STPUTS(p, buf);
return buf;
}
OpenPOWER on IntegriCloud