summaryrefslogtreecommitdiff
path: root/src/snapshot.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-13 19:22:05 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-13 19:22:05 +0300
commit01e1c61e9fcf4a0b0164a7fe5395a209a50f6905 (patch)
tree1f1eb33e49eab338650a42e8f602af75d8d28a24 /src/snapshot.c
parent2d02d39d2cd32e9eb559638865d2746f02c08556 (diff)
Optimize hot loops with direct access, LUTs, and closed-form formulas
Diffstat (limited to 'src/snapshot.c')
-rw-r--r--src/snapshot.c21
1 files changed, 15 insertions, 6 deletions
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;