aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-06-18 15:53:15 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-06-24 15:30:48 +0000
commit81131e3a8757658be264e2069c75406993b8e876 (patch)
tree8ddcfcec653d73b5d69f4b84b4d47e91cf0ebc04
parentvt: utf8: de-duplicate; jump to end of function to print to grid (diff)
vt: utf8: don’t scan *all* previous chains
When checking if we already have a compose chain for the current sequence of characters, don’t search the list from the beginning, unless we have to. Taking the following things into consideration: * New compose chains are always appended at the end of the list * If the current sequence is 3 or more characters, it *must* consist of an existing compose chain, plus the new character. Thus, when searching, start at index 0 if we only have two characters, since then the base cell originally contained a regular base character, and not a compose chain. I.e. the new chain may be _anywhere_ in the chain list. If however we have a sequence of three or more characters, start at the index the *base* chain was at. If the chain we’re searching for exists, it *must* have been added *after* the base chain, and thus it *must* be located *after* the base chain in the chain list.
-rw-r--r--vt.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/vt.c b/vt.c
index e516735d..bbe6fc9a 100644
--- a/vt.c
+++ b/vt.c
@@ -611,6 +611,7 @@ 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;
+ size_t search_start_index = 0;
/* Is base cell already a cluster? */
const struct composed *composed =
@@ -620,6 +621,7 @@ action_utf8_print(struct terminal *term, wchar_t wc)
: NULL;
if (composed != NULL) {
+ search_start_index = base - CELL_COMB_CHARS_LO;
base = composed->chars[0];
last = composed->chars[composed->count - 1];
}
@@ -692,7 +694,7 @@ action_utf8_print(struct terminal *term, wchar_t wc)
xassert(wanted_count <= ALEN(composed->chars));
/* Look for existing combining chain */
- for (size_t i = 0; i < term->composed_count; i++) {
+ for (size_t i = search_start_index; i < term->composed_count; i++) {
const struct composed *cc = &term->composed[i];
if (cc->chars[0] != base)