aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-06-24 17:18:06 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-06-24 17:18:06 +0000
commit88ce0e437518eee07de99ac51474e03e897bf287 (patch)
tree0e56fadc48ec587b1b1f82c5e0d2405f9b58decc
parentterm: CELL_COMB_CHARS chars are keys, not indices -> more range is better (diff)
vt: improved key hash algorithm -> reduces number of key collisions
-rw-r--r--vt.c13
1 files 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)