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:
Daniel Eklöf 2019-08-22 17:33:23 +02:00
parent f0663c951e
commit 7c7720a3ab
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
5 changed files with 107 additions and 56 deletions

View file

@ -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);