mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-29 06:46:35 -04:00
term: cache currently selected charset
vt.c::action_print(), which is in the hot path, needs to lookup the currently selected charset. This currently requires two loads; first to load the current charset *index*, and then another to get _which_ charset is currently mapped to that index. By caching the current charset, we only need one load. We need to update the cache when: * A different charset index is selected (i.e. SO/SI) * The charset for the current index is changed (e.g. ‘\E(0’, ‘\E(B’ etc) * We restore saved charsets
This commit is contained in:
parent
c5c3447ca8
commit
aa8902a6ef
3 changed files with 12 additions and 6 deletions
|
|
@ -2335,6 +2335,7 @@ term_restore_cursor(struct terminal *term, const struct cursor *cursor)
|
||||||
|
|
||||||
term->vt.attrs = term->vt.saved_attrs;
|
term->vt.attrs = term->vt.saved_attrs;
|
||||||
term->charsets = term->saved_charsets;
|
term->charsets = term->saved_charsets;
|
||||||
|
term->charset = term->charsets.set[term->charsets.selected];
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
||||||
|
|
@ -280,6 +280,7 @@ struct terminal {
|
||||||
|
|
||||||
struct charsets charsets;
|
struct charsets charsets;
|
||||||
struct charsets saved_charsets; /* For save/restore cursor + attributes */
|
struct charsets saved_charsets; /* For save/restore cursor + attributes */
|
||||||
|
enum charset charset; /* cached copy of charsets.set[charsets.selected] */
|
||||||
|
|
||||||
bool auto_margin;
|
bool auto_margin;
|
||||||
bool insert_mode;
|
bool insert_mode;
|
||||||
|
|
|
||||||
16
vt.c
16
vt.c
|
|
@ -184,11 +184,13 @@ action_execute(struct terminal *term, uint8_t c)
|
||||||
case '\x0e':
|
case '\x0e':
|
||||||
/* SO - shift out */
|
/* SO - shift out */
|
||||||
term->charsets.selected = 1; /* G1 */
|
term->charsets.selected = 1; /* G1 */
|
||||||
|
term->charset = term->charsets.set[1];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '\x0f':
|
case '\x0f':
|
||||||
/* SI - shift in */
|
/* SI - shift in */
|
||||||
term->charsets.selected = 0; /* G0 */
|
term->charsets.selected = 0; /* G0 */
|
||||||
|
term->charset = term->charsets.set[0];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -238,13 +240,10 @@ action_print(struct terminal *term, uint8_t c)
|
||||||
L'│', L'≤', L'≥', L'π', L'≠', L'£', L'·', /* x - ~ */
|
L'│', L'≤', L'≥', L'π', L'≠', L'£', L'·', /* x - ~ */
|
||||||
};
|
};
|
||||||
|
|
||||||
if (unlikely(term->charsets.set[term->charsets.selected] == CHARSET_GRAPHIC) &&
|
if (unlikely(term->charset == CHARSET_GRAPHIC) && c >= 0x60 && c <= 0x7e)
|
||||||
c >= 0x60 && c <= 0x7e)
|
|
||||||
{
|
|
||||||
term_print(term, vt100_0[c - 0x60], 1);
|
term_print(term, vt100_0[c - 0x60], 1);
|
||||||
} else {
|
else
|
||||||
term_print(term, c, 1);
|
term_print(term, c, 1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -414,11 +413,13 @@ action_esc_dispatch(struct terminal *term, uint8_t final)
|
||||||
case 'N':
|
case 'N':
|
||||||
/* SS2 - Single Shift 2 */
|
/* SS2 - Single Shift 2 */
|
||||||
term->charsets.selected = 2; /* G2 */
|
term->charsets.selected = 2; /* G2 */
|
||||||
|
term->charset = term->charsets.set[2];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'O':
|
case 'O':
|
||||||
/* SS3 - Single Shift 3 */
|
/* SS3 - Single Shift 3 */
|
||||||
term->charsets.selected = 3; /* G3 */
|
term->charsets.selected = 3; /* G3 */
|
||||||
|
term->charset = term->charsets.set[3];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '\\':
|
case '\\':
|
||||||
|
|
@ -453,6 +454,8 @@ action_esc_dispatch(struct terminal *term, uint8_t final)
|
||||||
'+' ? 3 : -1;
|
'+' ? 3 : -1;
|
||||||
xassert(idx != -1);
|
xassert(idx != -1);
|
||||||
term->charsets.set[idx] = CHARSET_GRAPHIC;
|
term->charsets.set[idx] = CHARSET_GRAPHIC;
|
||||||
|
if (idx == term->charsets.selected)
|
||||||
|
term->charset = CHARSET_GRAPHIC;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -465,7 +468,8 @@ action_esc_dispatch(struct terminal *term, uint8_t final)
|
||||||
'+' ? 3 : -1;
|
'+' ? 3 : -1;
|
||||||
xassert(idx != -1);
|
xassert(idx != -1);
|
||||||
term->charsets.set[idx] = CHARSET_ASCII;
|
term->charsets.set[idx] = CHARSET_ASCII;
|
||||||
|
if (idx == term->charsets.selected)
|
||||||
|
term->charset = CHARSET_ASCII;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue