diff --git a/src/Screen.zig b/src/Screen.zig index a4e6526..8748e3e 100644 --- a/src/Screen.zig +++ b/src/Screen.zig @@ -34,7 +34,7 @@ cursor_shape: Cell.CursorShape = .default, pub fn init(alloc: std.mem.Allocator, winsize: Winsize, unicode: *const Unicode) !Screen { const w = winsize.cols; const h = winsize.rows; - var self = Screen{ + const self = Screen{ .buf = try alloc.alloc(Cell, w * h), .width = w, .height = h, @@ -42,9 +42,8 @@ pub fn init(alloc: std.mem.Allocator, winsize: Winsize, unicode: *const Unicode) .height_pix = winsize.y_pixel, .unicode = unicode, }; - for (self.buf, 0..) |_, i| { - self.buf[i] = .{}; - } + const base_cell: Cell = .{}; + @memset(self.buf, base_cell); return self; } pub fn deinit(self: *Screen, alloc: std.mem.Allocator) void { diff --git a/src/Window.zig b/src/Window.zig index b93ccb8..526f6cc 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -206,11 +206,18 @@ pub fn gwidth(self: Window, str: []const u8) usize { /// fills the window with the provided cell pub fn fill(self: Window, cell: Cell) void { - var row: usize = self.y_off; - while (row < (self.height + self.y_off)) : (row += 1) { - var col: usize = self.x_off; - while (col < (self.width + self.x_off)) : (col += 1) { - self.screen.writeCell(col, row, cell); + if (self.x_off == 0 and self.width == self.screen.width) { + // we have a full width window, therefore contiguous memory. + const start = self.y_off * self.width; + const end = start + (self.height * self.width); + @memset(self.screen.buf[start..end], cell); + } else { + // Non-contiguous. Iterate over rows an memset + var row: usize = self.y_off; + while (row < (self.height + self.y_off)) : (row += 1) { + const start = self.x_off + (row * self.screen.width); + const end = start + self.width; + @memset(self.screen.buf[start..end], cell); } } }