aboutsummaryrefslogtreecommitdiff
path: root/commands.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-08-22 15:33:23 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-08-22 15:33:23 +0000
commit7c7720a3ab314e471499194f114797ca7a40afde (patch)
tree1113380cb5fa7456ccebf71ed72c1b9d9d672c14 /commands.c
parentgenerate-alt-random-writes: generate color, scroll and scroll region sequences (diff)
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.
Diffstat (limited to 'commands.c')
-rw-r--r--commands.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/commands.c b/commands.c
index 4fe50a8f..01e73981 100644
--- a/commands.c
+++ b/commands.c
@@ -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);