sh: Code size optimizations to buffered output.

This is mainly less use of the outc macro.

No functional change is intended, but code size is about 2K less on i386.
This commit is contained in:
Jilles Tjoelker 2010-11-20 14:14:52 +00:00
parent 8987b01ea9
commit aeb5d06504
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=215567
7 changed files with 39 additions and 34 deletions

View File

@ -699,13 +699,13 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
for (sp = varlist.list ; sp ; sp = sp->next) {
if (sep != 0)
out2c(' ');
p = sp->text;
while (*p != '=' && *p != '\0')
out2c(*p++);
if (*p != '\0') {
out2c(*p++);
p = strchr(sp->text, '=');
if (p != NULL) {
p++;
outbin(sp->text, p - sp->text, out2);
out2qstr(p);
}
} else
out2qstr(sp->text);
sep = ' ';
}
for (sp = arglist.list ; sp ; sp = sp->next) {

View File

@ -1592,9 +1592,7 @@ wordexpcmd(int argc, char **argv)
for (i = 1, len = 0; i < argc; i++)
len += strlen(argv[i]);
out1fmt("%08x", (int)len);
for (i = 1; i < argc; i++) {
out1str(argv[i]);
out1c('\0');
}
for (i = 1; i < argc; i++)
outbin(argv[i], strlen(argv[i]) + 1, out1);
return (0);
}

View File

@ -128,10 +128,8 @@ main(int argc, char *argv[])
exitshell(exitstatus);
}
reset();
if (exception == EXINT) {
out2c('\n');
flushout(&errout);
}
if (exception == EXINT)
out2fmt_flush("\n");
popstackmark(&smark);
FORCEINTON; /* enable interrupts */
if (state == 1)

View File

@ -261,13 +261,12 @@ minus_o(char *name, int val)
optlist[i].val ? "on" : "off");
} else {
/* Output suitable for re-input to shell. */
for (i = 0; i < NOPTS; i++) {
if (i % 6 == 0)
out1str(i == 0 ? "set" : "\nset");
out1fmt(" %co %s", optlist[i].val ? '-' : '+',
optlist[i].name);
}
out1c('\n');
for (i = 0; i < NOPTS; i++)
out1fmt("%s %co %s%s",
i % 6 == 0 ? "set" : "",
optlist[i].val ? '-' : '+',
optlist[i].name,
i % 6 == 5 || i == NOPTS - 1 ? "\n" : "");
}
} else {
for (i = 0; i < NOPTS; i++)

View File

@ -95,6 +95,12 @@ RESET {
#endif
void
outcslow(int c, struct output *file)
{
outc(c, file);
}
void
out1str(const char *p)
{
@ -149,19 +155,19 @@ outqstr(const char *p, struct output *file)
case '\'':
/* Can't quote single quotes inside single quotes. */
if (inquotes)
outc('\'', file);
outcslow('\'', file);
inquotes = 0;
outstr("\\'", file);
break;
default:
if (!inquotes)
outc('\'', file);
outcslow('\'', file);
inquotes = 1;
outc(ch, file);
}
}
if (inquotes)
outc('\'', file);
outcslow('\'', file);
}
void

View File

@ -54,6 +54,7 @@ extern struct output *out1; /* &memout if backquote, otherwise &output */
extern struct output *out2; /* &memout if backquote with 2>&1, otherwise
&errout */
void outcslow(int, struct output *);
void out1str(const char *);
void out1qstr(const char *);
void out2str(const char *);
@ -74,7 +75,7 @@ int xwrite(int, const char *, int);
#define outc(c, file) (--(file)->nleft < 0? (emptyoutbuf(file), *(file)->nextc++ = (c)) : (*(file)->nextc++ = (c)))
#define out1c(c) outc(c, out1);
#define out2c(c) outc(c, out2);
#define out2c(c) outcslow(c, out2);
#define OUTPUT_INCL
#endif

View File

@ -633,10 +633,10 @@ showvarscmd(int argc __unused, char **argv __unused)
qsort(vars, n, sizeof(*vars), var_compare);
for (i = 0; i < n; i++) {
for (s = vars[i]; *s != '='; s++)
out1c(*s);
out1c('=');
out1qstr(s + 1);
s = strchr(vars[i], '=');
s++;
outbin(vars[i], s - vars[i], out1);
out1qstr(s);
out1c('\n');
}
ckfree(vars);
@ -710,12 +710,15 @@ found:;
out1str(cmdname);
out1c(' ');
}
for (p = vp->text ; *p != '=' ; p++)
out1c(*p);
p = strchr(vp->text, '=');
if (values && !(vp->flags & VUNSET)) {
out1c('=');
out1qstr(p + 1);
}
p++;
outbin(vp->text, p - vp->text,
out1);
out1qstr(p);
} else
outbin(vp->text, p - vp->text,
out1);
out1c('\n');
}
}