mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
scrolling: optimize row access by assuming number of rows is a power of 2
With this assumption, we can replace 'a % b' with 'a & (b - 1)'. In terms of instructions, this means a fast 'and' instead of a slow 'div'. Further optimize scrolling by: * not double-initializing empty rows. Previously, grid_row_alloc() called calloc(), which was then followed by a memset() when scrolling. This is of course unnecessary. * Don't loop the entire set of visible rows (this was done to ensure all visible rows had been allocated, and to prefetch the cell contents). This isn't necessary; only newly pulled in rows can be NULL. For now, don't prefetch at all.
This commit is contained in:
parent
f0663c951e
commit
7c7720a3ab
5 changed files with 107 additions and 56 deletions
|
|
@ -19,7 +19,11 @@ cmd_scrollback_up(struct terminal *term, int rows)
|
|||
rows = min(rows, term->rows);
|
||||
assert(term->grid->offset >= 0);
|
||||
|
||||
int new_view = (term->grid->view + term->grid->num_rows - rows) % term->grid->num_rows;
|
||||
int new_view = term->grid->view - rows;
|
||||
while (new_view < 0)
|
||||
new_view += term->grid->num_rows;
|
||||
new_view %= term->grid->num_rows;
|
||||
|
||||
assert(new_view >= 0);
|
||||
assert(new_view < term->grid->num_rows);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue