From 88ce0e437518eee07de99ac51474e03e897bf287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 24 Jun 2021 19:18:06 +0200 Subject: [PATCH] vt: improved key hash algorithm -> reduces number of key collisions --- vt.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/vt.c b/vt.c index 7c77f7ec..e003887e 100644 --- a/vt.c +++ b/vt.c @@ -611,7 +611,6 @@ action_utf8_print(struct terminal *term, wchar_t wc) xassert(col >= 0 && col < term->cols); wchar_t base = row->cells[col].wc; wchar_t UNUSED last = base; - uint32_t key = base ^ wc; /* Is base cell already a cluster? */ const struct composed *composed = @@ -619,11 +618,18 @@ 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) { base = composed->chars[0]; last = composed->chars[composed->count - 1]; - key = composed->key ^ wc; - } + key = chain_key(composed->key, wc); + } else + key = chain_key(base, wc); + + #undef chain_key key &= CELL_COMB_CHARS_HI - CELL_COMB_CHARS_LO; @@ -706,6 +712,7 @@ action_utf8_print(struct terminal *term, wchar_t wc) * again. */ + xassert(key == cc->key); if (cc->chars[0] != base || cc->count != wanted_count || cc->chars[wanted_count - 1] != wc)