From 60b3ccc64115fb7e4b303eb1b93ba16d10fff1b5 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 14 Mar 2021 19:19:10 +0100 Subject: term: runtime switch between a ‘fast’ and a ‘generic’ ASCII print function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- vt.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'vt.c') diff --git a/vt.c b/vt.c index d94420da..af4691ea 100644 --- a/vt.c +++ b/vt.c @@ -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; } } -- cgit v1.3