chiark / gitweb /
Put bitmap data and alias target into a union
authorBen Harris <bjh21@bjh21.me.uk>
Thu, 18 Jul 2024 11:59:55 +0000 (12:59 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Sun, 18 Aug 2024 13:25:10 +0000 (14:25 +0100)
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.

bedstead.c

index 1031a3277a8f6213ae8292903c605bfd945610b0..ebdb1b3703f2c6543247c993c4b828173d94a861 100644 (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;
        /*