mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-04 04:06:06 -05:00
grid: reflow: don’t initialize newly allocated rows
We’re going to write to it immediately anyway. In most cases, *all* newly allocated, and zero-initialized, cells are overwritten. So let’s skip the zero-initialization of the new cells. There are two cases where we need to explicitly clear cells now: * When inserting a hard line break - erase the remaining cells * When done, the *last* row may not have been completely written - erase the remaining cells
This commit is contained in:
parent
ba23ee73e5
commit
11c7990ec8
1 changed files with 9 additions and 3 deletions
12
grid.c
12
grid.c
|
|
@ -341,11 +341,10 @@ _line_wrap(struct grid *old_grid, struct row **new_grid, struct row *row,
|
|||
|
||||
if (new_row == NULL) {
|
||||
/* Scrollback not yet full, allocate a completely new row */
|
||||
new_row = grid_row_alloc(col_count, true);
|
||||
new_row = grid_row_alloc(col_count, false);
|
||||
new_grid[*row_idx] = new_row;
|
||||
} else {
|
||||
/* Scrollback is full, need to re-use a row */
|
||||
memset(new_row->cells, 0, col_count * sizeof(new_row->cells[0]));
|
||||
grid_row_reset_extra(new_row);
|
||||
new_row->linebreak = false;
|
||||
|
||||
|
|
@ -451,7 +450,7 @@ grid_resize_and_reflow(
|
|||
struct row *new_row = new_grid[new_row_idx];
|
||||
|
||||
xassert(new_row == NULL);
|
||||
new_row = grid_row_alloc(new_cols, true);
|
||||
new_row = grid_row_alloc(new_cols, false);
|
||||
new_grid[new_row_idx] = new_row;
|
||||
|
||||
/* Start at the beginning of the old grid's scrollback. That is,
|
||||
|
|
@ -649,6 +648,9 @@ grid_resize_and_reflow(
|
|||
}
|
||||
|
||||
if (old_row->linebreak) {
|
||||
/* Erase the remaining cells */
|
||||
memset(&new_row->cells[new_col_idx], 0,
|
||||
(new_cols - new_col_idx) * sizeof(new_row->cells[0]));
|
||||
new_row->linebreak = true;
|
||||
line_wrap();
|
||||
}
|
||||
|
|
@ -657,6 +659,10 @@ grid_resize_and_reflow(
|
|||
#undef line_wrap
|
||||
}
|
||||
|
||||
/* Erase the remaining cells */
|
||||
memset(&new_row->cells[new_col_idx], 0,
|
||||
(new_cols - new_col_idx) * sizeof(new_row->cells[0]));
|
||||
|
||||
xassert(old_rows == 0 || *next_tp == &terminator);
|
||||
|
||||
#if defined(_DEBUG)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue