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.
This commit is contained in:
kre 2017-11-19 03:22:55 +00:00
parent 536abc0958
commit bfa0b331f0
2 changed files with 7 additions and 7 deletions

View File

@ -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 @@ __RCSID("$NetBSD: output.c,v 1.37 2017/11/16 19:41:02 kre Exp $");
#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;

View File

@ -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;
char *buf;
int bufsize;
char *buf;
short fd;
short flags;
};