aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-05-16 08:11:41 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-05-17 15:57:41 +0000
commit1aa4a31c6f8aaf6a504d080396d8aff1c2a39d87 (patch)
tree96a68557fa8628156caffbceb76537feb7115d67
parentgrid: reflow: don’t initialize newly allocated rows (diff)
grid: reflow: free old rows as soon as we’re done with them
This reduces the memory cost of reflowing text, as we no longer needs to hold both the old and the new grid, in their entirety, in memory at the same time.
-rw-r--r--grid.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/grid.c b/grid.c
index 996cf8d4..0e116793 100644
--- a/grid.c
+++ b/grid.c
@@ -655,6 +655,9 @@ grid_resize_and_reflow(
line_wrap();
}
+ grid_row_free(old_grid[old_row_idx]);
+ grid->rows[old_row_idx] = NULL;
+
#undef print_spacer
#undef line_wrap
}
@@ -678,6 +681,10 @@ grid_resize_and_reflow(
tll_foreach(row->extra->uri_ranges, it)
xassert(it->item.end >= 0);
}
+
+ /* Verify all old rows have been free:d */
+ for (int i = 0; i < old_rows; i++)
+ xassert(grid->rows[i] == NULL);
#endif
/* Set offset such that the last reflowed row is at the bottom */
@@ -711,9 +718,7 @@ grid_resize_and_reflow(
xassert(new_grid[idx] != NULL);
}
- /* Free old grid */
- for (int r = 0; r < grid->num_rows; r++)
- grid_row_free(old_grid[r]);
+ /* Free old grid (rows already free:d) */
free(grid->rows);
grid->rows = new_grid;