terminal: PageList updates page size accounting when erasing page

This commit is contained in:
Mitchell Hashimoto
2024-03-09 14:51:53 -08:00
parent bf79c040ce
commit 775049e1c0

View File

@ -1337,9 +1337,15 @@ fn createPage(self: *PageList, cap: Capacity) !*List.Node {
/// Destroy the memory of the given page and return it to the pool. The
/// page is assumed to already be removed from the linked list.
fn destroyPage(self: *PageList, page: *List.Node) void {
// Reset the memory to zero so it can be reused
@memset(page.data.memory, 0);
// Put it back into the allocator pool
self.pool.pages.destroy(@ptrCast(page.data.memory.ptr));
self.pool.nodes.destroy(page);
// Update our accounting for page size
self.page_size -= PagePool.item_size;
}
/// Erase the rows from the given top to bottom (inclusive). Erasing
@ -3087,6 +3093,26 @@ test "PageList erase" {
try testing.expect(s.pages.first == s.pages.last);
}
test "PageList erase reaccounts page size" {
const testing = std.testing;
const alloc = testing.allocator;
var s = try init(alloc, 80, 24, null);
defer s.deinit();
const start_size = s.page_size;
// Grow so we take up at least 5 pages.
const page = &s.pages.last.?.data;
for (0..page.capacity.rows * 5) |_| {
_ = try s.grow();
}
try testing.expect(s.page_size > start_size);
// Erase the entire history, we should be back to just our active set.
s.eraseRows(.{ .history = .{} }, null);
try testing.expectEqual(start_size, s.page_size);
}
test "PageList erase row with tracked pin resets to top-left" {
const testing = std.testing;
const alloc = testing.allocator;