From 3bad062f8a8f73b9271d42cc00b7c8a74fa82617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 24 Jun 2021 19:36:39 +0200 Subject: [PATCH] vt: utf8: rotate instead of just shifting when updating compose key This reduces the number of collisions in even more workloads. --- vt.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/vt.c b/vt.c index e003887e..ec011cad 100644 --- a/vt.c +++ b/vt.c @@ -585,6 +585,13 @@ action_put(struct terminal *term, uint8_t c) dcs_put(term, c); } +static inline uint32_t +chain_key(uint32_t old_key, uint32_t new_wc) +{ + /* Rotate left 8 bits, xor with new char */ + return ((old_key << 8) | (old_key >> (32 - 8))) ^ new_wc; +} + static void action_utf8_print(struct terminal *term, wchar_t wc) { @@ -618,8 +625,6 @@ action_utf8_print(struct terminal *term, wchar_t wc) ? composed_lookup(term->composed, base - CELL_COMB_CHARS_LO) : NULL; - #define chain_key(old, new) (((old) << 8) ^ (new)) - uint32_t key; if (composed != NULL) { @@ -629,8 +634,6 @@ action_utf8_print(struct terminal *term, wchar_t wc) } else key = chain_key(base, wc); - #undef chain_key - key &= CELL_COMB_CHARS_HI - CELL_COMB_CHARS_LO; #if defined(FOOT_GRAPHEME_CLUSTERING)