From 4d7993b36fa3f97e26c527c37b36eb9321b79791 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Fri, 2 Aug 2019 18:19:07 +0200 Subject: cell: pack more efficiently and store glyph as a wchar The 'attributes' struct is now 8 bytes and naturally packed (used to be 9 bytes, artificially packed). 'cell' struct is now 12 bytes, naturally packed (used to be 13 bytes, artificially packed). Furthermore, the glyph is stored as a wchar instead of a char*. This makes it easier (faster) to do glyph lookup when rendering. --- terminal.h | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'terminal.h') diff --git a/terminal.h b/terminal.h index 0d6f00f3..195ad26b 100644 --- a/terminal.h +++ b/terminal.h @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -50,28 +51,34 @@ struct rgb { float r, g, b; }; /* * Note: we want the cells to be as small as possible. Larger cells * means fewer scrollback lines (or performance drops due to cache - * misses) */ + * misses) + * + * Note that the members are laid out optimized for x86 + */ struct attributes { - uint8_t bold:1; - uint8_t dim:1; - uint8_t italic:1; - uint8_t underline:1; - uint8_t strikethrough:1; - uint8_t blink:1; - uint8_t conceal:1; - uint8_t reverse:1; + uint32_t bold:1; + uint32_t dim:1; + uint32_t italic:1; + uint32_t underline:1; + uint32_t strikethrough:1; + uint32_t blink:1; + uint32_t conceal:1; + uint32_t reverse:1; + uint32_t fg:24; uint32_t clean:1; - uint32_t foreground:31; - - uint32_t reserved:1; - uint32_t background:31; -} __attribute__((packed)); + uint32_t have_fg:1; + uint32_t have_bg:1; + uint32_t reserved:5; + uint32_t bg:24; +}; +static_assert(sizeof(struct attributes) == 8, "bad size"); struct cell { + wchar_t wc; struct attributes attrs; - char c[4]; -} __attribute__((packed)); +}; +static_assert(sizeof(struct cell) == 12, "bad size"); struct scroll_region { int start; -- cgit v1.3