Put bitmap data and alias target into a union

A character can't both be an alias and have its own bitmap data, so we
may as well overlap them.  Wrapping them in a union doesn't require any
changes to the syntax of the glyphs array because C allows for
incomplete bracketing of initialisers.  Because the union doesn't have a
name, its members can be accessed as though they're members of the
containing struct, which means that accesses to them don't need to
change.

There is a new flag to mark a glyph as an alias since "alias_of == NULL"
no longer works, and a corresponding change to the ALIAS() macro.

This saves about 20K of bedstead's data segment on a 64-bit system,
which is kind of silly but it's satisfying nonetheless.
This commit is contained in:
Ben Harris 2024-07-18 12:59:55 +01:00
parent f6a4441d41
commit 874a12b047

View File

@ -194,10 +194,13 @@ static void glyph_complement(void);
/* U(N) sets the code point and name of a glyph not in AGLFN */
#define U(N) 0x ## N, 0x ## N >= 0x10000 ? "u" #N : "uni" #N
#define ALIAS(alias, canonical) {{},-1,alias,0,canonical}
#define ALIAS(alias, canonical) {{.alias_of=canonical},-1,alias,IS_ALIAS}
static struct glyph {
char data[YSIZE];
union {
char data[YSIZE];
char const *alias_of;
};
int_least32_t unicode;
char const *name;
uint_least8_t flags;
@ -206,7 +209,7 @@ static struct glyph {
#define MOS4 0x04 /* 4-cell mosaic graphics character */
#define SEP6 (SEP | MOS6)
#define SEP4 (SEP | MOS4)
char const *alias_of;
#define IS_ALIAS 0x08
} glyphs[] = {
/*
* The first batch of glyphs comes from the code tables at the end of
@ -2859,7 +2862,7 @@ main(int argc, char **argv)
printf("Flags: HW\n");
printf("LayerCount: 2\n");
dolookups(&glyphs[i]);
if (glyphs[i].alias_of != NULL)
if (glyphs[i].flags & IS_ALIAS)
doalias(glyphs[i].alias_of);
else if (glyphs[i].flags & MOS6)
domosaic(glyphs[i].data[0],
@ -2998,7 +3001,7 @@ dopalt(struct glyph const *g)
unsigned char cols = 0;
int dx = 0, dh = 0;
while (g->alias_of != NULL)
while (g->flags & IS_ALIAS)
g = get_glyph_by_name(g->alias_of);
if (g->flags & (MOS6|MOS4)) return;
/*