aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-05-31 10:41:35 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-05-31 10:41:35 +0000
commitd9028b23944172cea94e70d5cf3d089e537716a5 (patch)
tree935724ce9d13e2d7878ee9be68179dbaeb37c70d
parentvt: utf8: don't need one entry action for each UTF8 variant (diff)
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().
-rw-r--r--vt.c10
1 files changed, 2 insertions, 8 deletions
diff --git a/vt.c b/vt.c
index 6472d173..0db90069 100644
--- a/vt.c
+++ b/vt.c
@@ -512,14 +512,8 @@ action_utf8_entry(struct terminal *term, uint8_t c)
static void
action_utf8_print(struct terminal *term, uint8_t c)
{
- /* Convert to wchar */
- mbstate_t ps = {};
- 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;
+ wchar_t wc = 0;
+ mbtowc(&wc, (const char *)term->vt.utf8.data, term->vt.utf8.idx);
int width = wcwidth(wc);