diff --git a/src/terminal/Screen.zig b/src/terminal/Screen.zig index 5376864d2..1ecc1656e 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -566,7 +566,7 @@ fn scrollDelta(self: *Screen, delta: isize, grow: bool) !void { if (!grow) { self.viewport = @minimum( self.history, - self.viewport +| @intCast(usize, delta), + self.viewport + @intCast(usize, delta), ); return; } @@ -574,7 +574,7 @@ fn scrollDelta(self: *Screen, delta: isize, grow: bool) !void { // Add our delta to our viewport. If we're less than the max currently // allowed to scroll to the bottom (the end of the history), then we // have space and we just return. - self.viewport +|= @intCast(usize, delta); + self.viewport += @intCast(usize, delta); if (self.viewport <= self.history) return; // Our viewport is bigger than our max. The number of new rows we need @@ -610,10 +610,6 @@ fn scrollDelta(self: *Screen, delta: isize, grow: bool) !void { const rows_to_delete = rows_final - self.rowsCapacity(); self.viewport -= rows_to_delete; self.storage.deleteOldest(rows_to_delete * (self.cols + 1)); - - // If we grew down like this, we must be at the bottom. - assert(self.viewportIsBottom()); - break :deleted rows_to_delete; } else 0; diff --git a/src/terminal/circ_buf.zig b/src/terminal/circ_buf.zig index 59928df1b..1202874f7 100644 --- a/src/terminal/circ_buf.zig +++ b/src/terminal/circ_buf.zig @@ -112,6 +112,8 @@ pub fn CircBuf(comptime T: type, comptime default: T) type { /// Delete the oldest n values from the buffer. If there are less /// than n values in the buffer, it'll delete everything. pub fn deleteOldest(self: *Self, n: usize) void { + assert(n <= self.storage.len); + // Clear the values back to default const slices = self.getPtrSlice(0, n); for (slices) |slice| std.mem.set(T, slice, default); @@ -128,7 +130,8 @@ pub fn CircBuf(comptime T: type, comptime default: T) type { /// the end of our buffer. This never "rotates" the buffer because /// the offset can only be within the size of the buffer. pub fn getPtrSlice(self: *Self, offset: usize, slice_len: usize) [2][]T { - assert(slice_len > 0); + // Note: this assertion is very important, it hints the compiler + // which generates ~10% faster code than without it. assert(offset + slice_len <= self.capacity()); // End offset is the last offset (exclusive) for our slice.