diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2019-08-02 16:19:07 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2019-08-02 16:19:07 +0000 |
| commit | 4d7993b36fa3f97e26c527c37b36eb9321b79791 (patch) | |
| tree | 391b9125d821de5010b5f383813135882d54293d /vt.c | |
| parent | term: 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 'vt.c')
| -rw-r--r-- | vt.c | 49 |
1 files changed, 23 insertions, 26 deletions
@@ -728,33 +728,29 @@ action_print_utf8(struct terminal *term) print_insert(term); - //LOG_DBG("print: UTF8: %.*s", (int)term->vt.utf8.idx, term->vt.utf8.data); - memcpy(cell->c, term->vt.utf8.data, term->vt.utf8.idx); - cell->c[term->vt.utf8.idx] = '\0'; + mbstate_t ps = {0}; + if (mbrtowc(&cell->wc, (const char *)term->vt.utf8.data, term->vt.utf8.idx, &ps) < 0) + cell->wc = 0; + term->vt.utf8.idx = 0; cell->attrs = term->vt.attrs; - /* Hack: zero- and double-width characters */ - mbstate_t ps = {0}; - wchar_t wc; - if (mbrtowc(&wc, cell->c, 4, &ps) >= 0) { - int width = wcwidth(wc); - if (width <= 0) { - /* Skip post_print() below - i.e. don't advance cursor */ - return; - } + int width = wcwidth(cell->wc); + if (width <= 0) { + /* Skip post_print() below - i.e. don't advance cursor */ + return; + } - /* Advance cursor the 'additional' columns (last step is done - * by post_print()) */ - for (int i = 1; i < width && term->cursor.col < term->cols - 1; i++) { - term_cursor_right(term, 1); + /* Advance cursor the 'additional' columns (last step is done + * by post_print()) */ + for (int i = 1; i < width && term->cursor.col < term->cols - 1; i++) { + term_cursor_right(term, 1); - assert(term->cursor.col < term->cols); - struct cell *cell = &row->cells[term->cursor.col]; - cell->c[0] = '\0'; - cell->attrs.clean = 0; - } + assert(term->cursor.col < term->cols); + struct cell *cell = &row->cells[term->cursor.col]; + cell->wc = 0; + cell->attrs.clean = 0; } post_print(term); @@ -788,16 +784,17 @@ action_print(struct terminal *term, uint8_t c) c >= 0x41 && c <= 0x7e) { const char *glyph = vt100_0[c - 0x41]; - if (glyph != NULL) - strncpy(cell->c, glyph, sizeof(cell->c)); + if (glyph != NULL) { + mbstate_t ps = {0}; + if (mbrtowc(&cell->wc, glyph, strlen(glyph), &ps) < 0) + cell->wc = 0; + } } else { //LOG_DBG("print: ASCII: %c", c); - cell->c[0] = c; - cell->c[1] = '\0'; + cell->wc = c; } cell->attrs = term->vt.attrs; - post_print(term); } |
