make erase a bit more efficient

This commit is contained in:
Mitchell Hashimoto
2022-05-21 18:55:55 -07:00
parent c5fbe439f8
commit 9a48d0498d
2 changed files with 7 additions and 9 deletions

View File

@ -74,6 +74,11 @@ pub fn rowIterator(self: *const Screen) RowIterator {
return .{ .screen = self, .index = 0 }; return .{ .screen = self, .index = 0 };
} }
/// Get the visible portion of the screen.
pub fn getVisible(self: Screen) []Cell {
return self.storage;
}
/// Get a single row by index (0-indexed). /// Get a single row by index (0-indexed).
pub fn getRow(self: Screen, idx: usize) Row { pub fn getRow(self: Screen, idx: usize) Row {
// Get the index of the first byte of the the row at index. // Get the index of the first byte of the the row at index.

View File

@ -223,15 +223,8 @@ pub fn eraseDisplay(
) !void { ) !void {
switch (mode) { switch (mode) {
.complete => { .complete => {
var y: usize = 0; const all = self.screen.getVisible();
while (y < self.rows) : (y += 1) { std.mem.set(Screen.Cell, all, self.cursor.pen);
var x: usize = 0;
while (x < self.cols) : (x += 1) {
const cell = try self.getOrPutCell(alloc, x, y);
cell.* = self.cursor.pen;
cell.char = 0;
}
}
}, },
.below => { .below => {