aboutsummaryrefslogtreecommitdiff
path: root/terminal.h
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-08-02 16:19:07 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-08-02 16:19:07 +0000
commit4d7993b36fa3f97e26c527c37b36eb9321b79791 (patch)
tree391b9125d821de5010b5f383813135882d54293d /terminal.h
parentterm: implement reset (diff)
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.
Diffstat (limited to 'terminal.h')
-rw-r--r--terminal.h39
1 files changed, 23 insertions, 16 deletions
diff --git a/terminal.h b/terminal.h
index 0d6f00f3..195ad26b 100644
--- a/terminal.h
+++ b/terminal.h
@@ -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;