From 01e1c61e9fcf4a0b0164a7fe5395a209a50f6905 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Tue, 13 Oct 2026 19:22:05 +0300 Subject: Optimize hot loops with direct access, LUTs, and closed-form formulas --- src/snapshot.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/snapshot.c') diff --git a/src/snapshot.c b/src/snapshot.c index 3869be4..29ed98c 100644 --- a/src/snapshot.c +++ b/src/snapshot.c @@ -189,17 +189,26 @@ static bool term_snapshot_update_inner(struct term_snapshot *s, struct term *t) if (!all && rows > 1) { int cand_k = 0; /* Find candidate scroll offset k by checking where top rows moved. */ - for (int p = 0; p < 2 && p < rows - 1 && !cand_k; p++) { - uint64_t key = new_keys[p]; - if (!key) - continue; - for (int k = 1; p + k < rows; k++) { - if (s->keys[p + k] == key) { + uint64_t key0 = new_keys[0]; + if (key0) { + for (int k = 1; k < rows; k++) { + if (s->keys[k] == key0) { cand_k = k; break; } } } + if (!cand_k && rows > 2) { + uint64_t key1 = new_keys[1]; + if (key1) { + for (int k = 1; 1 + k < rows; k++) { + if (s->keys[1 + k] == key1) { + cand_k = k; + break; + } + } + } + } if (cand_k > 0) { int total = rows - cand_k; -- cgit v1.2.3