aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-06-24 17:36:39 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-06-24 17:36:39 +0000
commit3bad062f8a8f73b9271d42cc00b7c8a74fa82617 (patch)
treed74f4fab77c0cc7fb25a0bbddd05da767a5e0e6d
parentvt: improved key hash algorithm -> reduces number of key collisions (diff)
vt: utf8: rotate instead of just shifting when updating compose key
This reduces the number of collisions in even more workloads.
-rw-r--r--vt.c11
1 files 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)