Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/sh Rearrange "struct output" to be slightly more friendl...



details:   https://anonhg.NetBSD.org/src/rev/f628677774d7
branches:  trunk
changeset: 827933:f628677774d7
user:      kre <kre%NetBSD.org@localhost>
date:      Sun Nov 19 03:22:55 2017 +0000

description:
Rearrange "struct output" to be slightly more friendly (I think)
to I32 P64 systems - keep nextc first, as that's used in macros,
and nleft next, as that's used (and both are updated) in the same macro,
which is used frequently, this increases the chance they're in the
same cache line (unchanged from before).   Beyond that it matters less,
so just shuffle a bit to avoid internal padding when pointers are 64 bits.
Note that there are just 3 of these structs (currently), even if there was
to be a memory saving (there probably won't be, trailing padding will eat it)
it would be of the order of 12 or 24 bytes total, so all this really
just panders to my sense of rightness....

Note to anyone who might be tempted, please don't update the struct
initializers to use newer C forms - eventually sh is planned to become
a host tool, and a separable package, so it wants to remain able to be
compiled using older (though at least ansi) compilers that implement only
older C variants.

diffstat:

 bin/sh/output.c |  10 +++++-----
 bin/sh/output.h |   4 ++--
 2 files changed, 7 insertions(+), 7 deletions(-)

diffs (50 lines):

diff -r 180a5867fb2a -r f628677774d7 bin/sh/output.c
--- a/bin/sh/output.c   Sun Nov 19 01:46:29 2017 +0000
+++ b/bin/sh/output.c   Sun Nov 19 03:22:55 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: output.c,v 1.37 2017/11/16 19:41:02 kre Exp $  */
+/*     $NetBSD: output.c,v 1.38 2017/11/19 03:22:55 kre Exp $  */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)output.c   8.2 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: output.c,v 1.37 2017/11/16 19:41:02 kre Exp $");
+__RCSID("$NetBSD: output.c,v 1.38 2017/11/19 03:22:55 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -74,9 +74,9 @@
 #define MEM_OUT -3             /* output to dynamically allocated memory */
 
 
-struct output output = {NULL, 0, NULL, OUTBUFSIZ, 1, 0};
-struct output errout = {NULL, 0, NULL, 100, 2, 0};
-struct output memout = {NULL, 0, NULL, 0, MEM_OUT, 0};
+struct output output = {NULL, 0, OUTBUFSIZ, NULL, 1, 0};
+struct output errout = {NULL, 0, 100, NULL, 2, 0};
+struct output memout = {NULL, 0, 0, NULL, MEM_OUT, 0};
 struct output *out1 = &output;
 struct output *out2 = &errout;
 
diff -r 180a5867fb2a -r f628677774d7 bin/sh/output.h
--- a/bin/sh/output.h   Sun Nov 19 01:46:29 2017 +0000
+++ b/bin/sh/output.h   Sun Nov 19 03:22:55 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: output.h,v 1.24 2012/03/15 02:02:20 joerg Exp $        */
+/*     $NetBSD: output.h,v 1.25 2017/11/19 03:22:55 kre Exp $  */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -41,8 +41,8 @@
 struct output {
        char *nextc;
        int nleft;
+       int bufsize;
        char *buf;
-       int bufsize;
        short fd;
        short flags;
 };



Home | Main Index | Thread Index | Old Index