mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-21 05:33:45 -04:00
vt: utf8: use mbtowc() instead of mbrtowc()
This is slightly faster, since we don't need to initialize an mbstate_t struct (using mbrtowc() with a NULL-pointer for 'ps' also works). Also, avoid a branch by setting wc=0 and then ignoring the result/error code from mbtowc().
This commit is contained in:
parent
c38b9be6a4
commit
d9028b2394
1 changed files with 2 additions and 8 deletions
10
vt.c
10
vt.c
|
|
@ -512,14 +512,8 @@ action_utf8_entry(struct terminal *term, uint8_t c)
|
||||||
static void
|
static void
|
||||||
action_utf8_print(struct terminal *term, uint8_t c)
|
action_utf8_print(struct terminal *term, uint8_t c)
|
||||||
{
|
{
|
||||||
/* Convert to wchar */
|
wchar_t wc = 0;
|
||||||
mbstate_t ps = {};
|
mbtowc(&wc, (const char *)term->vt.utf8.data, term->vt.utf8.idx);
|
||||||
wchar_t wc;
|
|
||||||
size_t count = mbrtowc(
|
|
||||||
&wc, (const char *)term->vt.utf8.data, term->vt.utf8.idx, &ps);
|
|
||||||
|
|
||||||
if ((ssize_t)count < 0)
|
|
||||||
wc = 0;
|
|
||||||
|
|
||||||
int width = wcwidth(wc);
|
int width = wcwidth(wc);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue