summaryrefslogtreecommitdiffstats
path: root/bin/sh
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2010-11-20 14:14:52 +0000
committerjilles <jilles@FreeBSD.org>2010-11-20 14:14:52 +0000
commit6915411ab291af6eba93647d13c0aa6714621fa2 (patch)
treebb660239ff9ba03cd107817f9d8d00fabdba49a1 /bin/sh
parent6a4a2e62a216ff7f70e10196bcdc7b3f4f76cad8 (diff)
downloadFreeBSD-src-6915411ab291af6eba93647d13c0aa6714621fa2.zip
FreeBSD-src-6915411ab291af6eba93647d13c0aa6714621fa2.tar.gz
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.
Diffstat (limited to 'bin/sh')
-rw-r--r--bin/sh/eval.c12
-rw-r--r--bin/sh/expand.c6
-rw-r--r--bin/sh/main.c6
-rw-r--r--bin/sh/options.c13
-rw-r--r--bin/sh/output.c12
-rw-r--r--bin/sh/output.h3
-rw-r--r--bin/sh/var.c21
7 files changed, 39 insertions, 34 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c
index 415b9eb..c306e73 100644
--- a/bin/sh/eval.c
+++ b/bin/sh/eval.c
@@ -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) {
diff --git a/bin/sh/expand.c b/bin/sh/expand.c
index 200da3f..d251ed0 100644
--- a/bin/sh/expand.c
+++ b/bin/sh/expand.c
@@ -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);
}
diff --git a/bin/sh/main.c b/bin/sh/main.c
index 83a62a7..9298f69 100644
--- a/bin/sh/main.c
+++ b/bin/sh/main.c
@@ -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)
diff --git a/bin/sh/options.c b/bin/sh/options.c
index af80036..389e555 100644
--- a/bin/sh/options.c
+++ b/bin/sh/options.c
@@ -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++)
diff --git a/bin/sh/output.c b/bin/sh/output.c
index d7fc534..8442a22 100644
--- a/bin/sh/output.c
+++ b/bin/sh/output.c
@@ -96,6 +96,12 @@ RESET {
void
+outcslow(int c, struct output *file)
+{
+ outc(c, file);
+}
+
+void
out1str(const char *p)
{
outstr(p, out1);
@@ -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
diff --git a/bin/sh/output.h b/bin/sh/output.h
index a7c748e..5e3b048 100644
--- a/bin/sh/output.h
+++ b/bin/sh/output.h
@@ -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
diff --git a/bin/sh/var.c b/bin/sh/var.c
index 3bba368..6c0618f 100644
--- a/bin/sh/var.c
+++ b/bin/sh/var.c
@@ -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');
}
}
OpenPOWER on IntegriCloud