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.
This commit is contained in:
Daniel Eklöf 2019-08-02 18:19:07 +02:00
parent ab92abbd21
commit 4d7993b36f
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
9 changed files with 146 additions and 129 deletions

View file

@ -3,6 +3,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <wchar.h>
#include <threads.h>
#include <semaphore.h>
@ -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;