Author: jilles
Date: Sat Nov 20 14:14:52 2010
New Revision: 215567
URL: http://svn.freebsd.org/changeset/base/215567

Log:
  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.

Modified:
  head/bin/sh/eval.c
  head/bin/sh/expand.c
  head/bin/sh/main.c
  head/bin/sh/options.c
  head/bin/sh/output.c
  head/bin/sh/output.h
  head/bin/sh/var.c

Modified: head/bin/sh/eval.c
==============================================================================
--- head/bin/sh/eval.c  Sat Nov 20 13:30:48 2010        (r215566)
+++ head/bin/sh/eval.c  Sat Nov 20 14:14:52 2010        (r215567)
@@ -699,13 +699,13 @@ evalcommand(union node *cmd, int flags, 
                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) {

Modified: head/bin/sh/expand.c
==============================================================================
--- head/bin/sh/expand.c        Sat Nov 20 13:30:48 2010        (r215566)
+++ head/bin/sh/expand.c        Sat Nov 20 14:14:52 2010        (r215567)
@@ -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);
 }

Modified: head/bin/sh/main.c
==============================================================================
--- head/bin/sh/main.c  Sat Nov 20 13:30:48 2010        (r215566)
+++ head/bin/sh/main.c  Sat Nov 20 14:14:52 2010        (r215567)
@@ -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)

Modified: head/bin/sh/options.c
==============================================================================
--- head/bin/sh/options.c       Sat Nov 20 13:30:48 2010        (r215566)
+++ head/bin/sh/options.c       Sat Nov 20 14:14:52 2010        (r215567)
@@ -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++)

Modified: head/bin/sh/output.c
==============================================================================
--- head/bin/sh/output.c        Sat Nov 20 13:30:48 2010        (r215566)
+++ head/bin/sh/output.c        Sat Nov 20 14:14:52 2010        (r215567)
@@ -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 *fi
                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

Modified: head/bin/sh/output.h
==============================================================================
--- head/bin/sh/output.h        Sat Nov 20 13:30:48 2010        (r215566)
+++ head/bin/sh/output.h        Sat Nov 20 14:14:52 2010        (r215567)
@@ -54,6 +54,7 @@ extern struct output *out1; /* &memout i
 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

Modified: head/bin/sh/var.c
==============================================================================
--- head/bin/sh/var.c   Sat Nov 20 13:30:48 2010        (r215566)
+++ head/bin/sh/var.c   Sat Nov 20 14:14:52 2010        (r215567)
@@ -633,10 +633,10 @@ showvarscmd(int argc __unused, char **ar
 
        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');
                                }
                        }
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to