diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2021-03-14 18:19:10 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2021-03-16 07:45:18 +0000 |
| commit | 60b3ccc64115fb7e4b303eb1b93ba16d10fff1b5 (patch) | |
| tree | 1c9559769b3006e573b6774d6adbe791138b9c85 /vt.c | |
| parent | Merge branch 'term-print-assume-col-can-be-incremented' (diff) | |
term: runtime switch between a ‘fast’ and a ‘generic’ ASCII print function
term_print() is called whenever the client application “prints”
something to the grid. It is called for both ASCII and UTF-8
characters, and needs to handle sixels, insert mode and ASCII
vs. graphical charsets.
Since it’s on the hot path, this becomes unnecessarily slow.
This patch adds a “fast” version of term_print(), tailored for the
common case: ASCII characters in non-insert mode, without any sixels
and non-graphical charsets.
A new function, term_update_ascii_printer(), has been added, and must
be called whenever:
* The currently selected charset *index* changes
* The currently selected charset changes (from ASCII to graphical, or
vice verse)
* Sixels are added to the grid
* Sixels are removed from the grid
* Insert mode is enabled/disabled
Diffstat (limited to 'vt.c')
| -rw-r--r-- | vt.c | 23 |
1 files changed, 7 insertions, 16 deletions
@@ -184,11 +184,13 @@ action_execute(struct terminal *term, uint8_t c) case '\x0e': /* SO - shift out */ term->charsets.selected = 1; /* G1 */ + term_update_ascii_printer(term); break; case '\x0f': /* SI - shift in */ term->charsets.selected = 0; /* G0 */ + term_update_ascii_printer(term); break; /* @@ -230,21 +232,7 @@ action_execute(struct terminal *term, uint8_t c) static void action_print(struct terminal *term, uint8_t c) { - /* 0x60 - 0x7e */ - static const wchar_t vt100_0[] = { - L'◆', L'▒', L'␉', L'␌', L'␍', L'␊', L'°', L'±', /* ` - g */ - L'', L'␋', L'┘', L'┐', L'┌', L'└', L'┼', L'⎺', /* h - o */ - L'⎻', L'─', L'⎼', L'⎽', L'├', L'┤', L'┴', L'┬', /* p - w */ - L'│', L'≤', L'≥', L'π', L'≠', L'£', L'·', /* x - ~ */ - }; - - if (unlikely(term->charsets.set[term->charsets.selected] == CHARSET_GRAPHIC) && - c >= 0x60 && c <= 0x7e) - { - term_print(term, vt100_0[c - 0x60], 1); - } else { - term_print(term, c, 1); - } + term->ascii_printer(term, c); } static void @@ -414,11 +402,13 @@ action_esc_dispatch(struct terminal *term, uint8_t final) case 'N': /* SS2 - Single Shift 2 */ term->charsets.selected = 2; /* G2 */ + term_update_ascii_printer(term); break; case 'O': /* SS3 - Single Shift 3 */ term->charsets.selected = 3; /* G3 */ + term_update_ascii_printer(term); break; case '\\': @@ -453,6 +443,7 @@ action_esc_dispatch(struct terminal *term, uint8_t final) '+' ? 3 : -1; xassert(idx != -1); term->charsets.set[idx] = CHARSET_GRAPHIC; + term_update_ascii_printer(term); break; } @@ -465,7 +456,7 @@ action_esc_dispatch(struct terminal *term, uint8_t final) '+' ? 3 : -1; xassert(idx != -1); term->charsets.set[idx] = CHARSET_ASCII; - + term_update_ascii_printer(term); break; } } |
