sixel: insert: calculate end rows in a single statement

This commit is contained in:
Daniel Eklöf 2020-06-28 10:45:05 +02:00
parent 4a0042ba15
commit 0483466f68
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

29
sixel.c
View file

@ -93,23 +93,36 @@ sixel_insert(struct terminal *term, struct sixel sixel)
const int scrollback_end const int scrollback_end
= (term->grid->offset + term->rows) & (term->grid->num_rows - 1); = (term->grid->offset + term->rows) & (term->grid->num_rows - 1);
int end_row = sixel.pos.row + sixel.rows - scrollback_end; const int end_row
while (end_row < 0) = (sixel.pos.row + sixel.rows
end_row += term->grid->num_rows; - scrollback_end
+ term->grid->num_rows) & (term->grid->num_rows - 1);
assert(end_row >= 0 && end_row < term->grid->num_rows);
tll_foreach(term->grid->sixel_images, it) { tll_foreach(term->grid->sixel_images, it) {
int e = it->item.pos.row + it->item.rows - scrollback_end; const int e
e -= scrollback_end; = (it->item.pos.row + it->item.rows
while (e < 0) - scrollback_end
e += term->grid->num_rows; + term->grid->num_rows) & (term->grid->num_rows - 1);
assert(e >= 0 && e < term->grid->num_rows);
if (e < end_row) { if (e < end_row) {
tll_insert_before(term->grid->sixel_images, it, sixel); tll_insert_before(term->grid->sixel_images, it, sixel);
return; goto out;
} }
} }
tll_push_back(term->grid->sixel_images, sixel); tll_push_back(term->grid->sixel_images, sixel);
out:
#if defined(LOG_ENABLE_DBG) && LOG_ENABLE_DBG
LOG_DBG("sixel list after insertion:");
tll_foreach(term->grid->sixel_images, it) {
LOG_DBG(" rows=%d+%d", it->item.pos.row, it->item.rows);
}
#else
;
#endif
} }
/* Row numbers are absolute */ /* Row numbers are absolute */