vt: don’t call wcwidth() on all combining characters every time we add

We already have all the widths needed to calculate the new one; it’s
the base characters width (base_width), or the previous combining
chain’s width (composed->width) plus the new characters’s
width (width).
This commit is contained in:
Daniel Eklöf 2021-06-15 07:38:27 +02:00
parent 09431dd15c
commit 57e636dd8e
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

18
vt.c
View file

@ -700,7 +700,7 @@ action_utf8_print(struct terminal *term, wchar_t wc)
if (cc->count != wanted_count)
continue;
if (cc->chars[0] != base)
if (cc->chars[0] != base)
continue;
bool match = true;
@ -732,16 +732,12 @@ action_utf8_print(struct terminal *term, wchar_t wc)
new_cc.chars[wanted_count - 1] = wc;
if (term->composed_count < CELL_COMB_CHARS_HI) {
int grapheme_width = wcwidth(base);
int min_grapheme_width = 0;
for (size_t i = 0; i < wanted_count; i++) {
wchar_t c = new_cc.chars[i];
if (c == 0xfe0f)
min_grapheme_width = 2;
grapheme_width += wcwidth(c);
}
new_cc.width = max(grapheme_width, min_grapheme_width);
int grapheme_width = composed != NULL ? composed->width : base_width;
if (wc == 0xfe0f && grapheme_width < 2)
grapheme_width = 2;
else
grapheme_width += width;
new_cc.width = grapheme_width;
term->composed_count++;
term->composed = xrealloc(term->composed, term->composed_count * sizeof(term->composed[0]));