aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-06-28 17:22:23 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-06-28 17:22:23 +0000
commit1140dd37d3d50f9ef003957f877464005d1ede11 (patch)
treee8d87840d401f40da61f370e65f02c2034dba2bb
parentMerge branch 'master' into sixel-performance (diff)
sixel: overwrite-by-rectangle: optimize: break out of loop as soon as possible
Since the images are sorted, we can break out of the loop as soon as we detect an image that *ends before* the rectangle's top starts. In order for the row comparisons to work, the row numbers must be re-based against the current scrollback offset, or the scrollback *end*, to be precise.
-rw-r--r--sixel.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/sixel.c b/sixel.c
index ba7566f0..429a7c66 100644
--- a/sixel.c
+++ b/sixel.c
@@ -344,12 +344,30 @@ _sixel_overwrite_by_rectangle(
const int start = row;
const int end = row + height - 1;
+ const int scrollback_end
+ = (term->grid->offset + term->rows) & (term->grid->num_rows - 1);
+
+ const int grid_relative_start
+ = (start
+ - scrollback_end
+ + term->grid->num_rows) & (term->grid->num_rows - 1);
+
tll_foreach(term->grid->sixel_images, it) {
struct sixel *six = &it->item;
const int six_start = six->pos.row;
const int six_end = (six_start + six->rows - 1) & (term->grid->num_rows - 1);
+ const int six_grid_relative_end =
+ (six_end
+ - scrollback_end
+ + + term->grid->num_rows) & (term->grid->num_rows - 1);
+
+ if (six_grid_relative_end < grid_relative_start) {
+ /* All remaining sixels are *before* our rectangle */
+ break;
+ }
+
/* We should never generate scrollback wrapping sixels */
assert(six_end >= six_start);