term: performance: use a bitfield to track which ascii printer to use

The things affecting which ASCII printer we use have grown...

Instead of checking everything inside term_update_ascii_printer(), use
a bitfield.

Anything affecting the printer used, must now set a bit in this
bitfield. This makes term_update_ascii_printer() much faster, since
all it needs to do is check if the bitfield is zero or not.
This commit is contained in:
Daniel Eklöf 2024-06-24 01:26:57 +02:00
parent 22302d8bcc
commit 48cf57818d
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
5 changed files with 63 additions and 13 deletions

View file

@ -2023,6 +2023,7 @@ term_reset(struct terminal *term, bool hard)
term_ime_enable(term);
#endif
term->bits_affecting_ascii_printer.value = 0;
term_update_ascii_printer(term);
if (!hard)
@ -3021,6 +3022,9 @@ term_restore_cursor(struct terminal *term, const struct cursor *cursor)
term->vt.attrs = term->vt.saved_attrs;
term->charsets = term->saved_charsets;
term->bits_affecting_ascii_printer.charset =
term->charsets.set[term->charsets.selected] != CHARSET_ASCII;
term_update_ascii_printer(term);
}
@ -3801,21 +3805,21 @@ ascii_printer_single_shift(struct terminal *term, char32_t wc)
{
ascii_printer_generic(term, wc);
term->charsets.selected = term->charsets.saved;
term->bits_affecting_ascii_printer.charset =
term->charsets.set[term->charsets.selected] != CHARSET_ASCII;
term_update_ascii_printer(term);
}
void
term_update_ascii_printer(struct terminal *term)
{
_Static_assert(sizeof(term->bits_affecting_ascii_printer) == sizeof(uint8_t), "bad size");
void (*new_printer)(struct terminal *term, char32_t wc) =
unlikely(tll_length(term->grid->sixel_images) > 0 ||
term->vt.osc8.uri != NULL ||
term->vt.curly.style > CURLY_SINGLE ||
term->vt.curly.color_src != COLOR_DEFAULT ||
term->charsets.set[term->charsets.selected] == CHARSET_GRAPHIC ||
term->insert_mode)
? &ascii_printer_generic
: &ascii_printer_fast;
unlikely(term->bits_affecting_ascii_printer.value != 0)
? &ascii_printer_generic
: &ascii_printer_fast;
#if defined(_DEBUG) && LOG_ENABLE_DBG
if (term->ascii_printer != new_printer) {
@ -4108,6 +4112,8 @@ term_osc8_open(struct terminal *term, uint64_t id, const char *uri)
term->vt.osc8.id = id;
term->vt.osc8.uri = xstrdup(uri);
term->bits_affecting_ascii_printer.osc8 = true;
term_update_ascii_printer(term);
}
@ -4117,6 +4123,7 @@ term_osc8_close(struct terminal *term)
free(term->vt.osc8.uri);
term->vt.osc8.uri = NULL;
term->vt.osc8.id = 0;
term->bits_affecting_ascii_printer.osc8 = false;
term_update_ascii_printer(term);
}