small optimizations

This commit is contained in:
Mitchell Hashimoto
2022-09-01 18:36:27 -07:00
parent 30a14d230e
commit 73581eee0b
3 changed files with 15 additions and 11 deletions

View File

@ -1291,11 +1291,13 @@ fn ttyRead(t: *libuv.Tty, n: isize, buf: []const u8) void {
// C0 execute, let our stream handle this one but otherwise
// continue since we're guaranteed to be back in ground.
.execute => win.terminal_stream.next(c) catch |err|
.execute => win.terminal_stream.execute(c) catch |err|
log.err("error processing terminal data: {}", .{err}),
// Otherwise, break out and go the slow path until we're
// back in ground.
// back in ground. There is a slight optimization here where
// could try to find the next transition to ground but when
// I implemented that it didn't materially change performance.
else => break,
}
@ -1304,7 +1306,6 @@ fn ttyRead(t: *libuv.Tty, n: isize, buf: []const u8) void {
}
if (i < end) {
//log.warn("SLOW={}", .{end - i});
win.terminal_stream.nextSlice(buf[i..end]) catch |err|
log.err("error processing terminal data: {}", .{err});
}
@ -1418,7 +1419,9 @@ pub fn horizontalTab(self: *Window) !void {
}
pub fn linefeed(self: *Window) !void {
try self.terminal.linefeed();
// Small optimization: call index instead of linefeed because they're
// identical and this avoids one layer of function call overhead.
try self.terminal.index();
}
pub fn carriageReturn(self: *Window) !void {

View File

@ -319,20 +319,21 @@ pub const RowIndexTag = enum {
/// The max length for a given tag. This is a length, not an index,
/// so it is 1-indexed. If the value is zero, it means that this
/// section of the screen is empty or disabled.
pub fn maxLen(self: RowIndexTag, screen: *const Screen) usize {
const rows_written = screen.rowsWritten();
pub inline fn maxLen(self: RowIndexTag, screen: *const Screen) usize {
return switch (self) {
// Screen can be any of the written rows
.screen => rows_written,
.screen => screen.rowsWritten(),
// Viewport can be any of the written rows or the max size
// of a viewport.
.viewport => @minimum(screen.rows, rows_written),
.viewport => @minimum(screen.rows, screen.rowsWritten()),
// History is all the way up to the top of our active area. If
// we haven't filled our active area, there is no history.
.history => if (rows_written > screen.rows) rows_written - screen.rows else 0,
.history => history: {
const rows_written = screen.rowsWritten();
break :history if (rows_written > screen.rows) rows_written - screen.rows else 0;
},
// Active area can be any number of rows. We ignore rows
// written here because this is the only row index that can

View File

@ -68,7 +68,7 @@ pub fn Stream(comptime Handler: type) type {
}
}
fn execute(self: *Self, c: u8) !void {
pub fn execute(self: *Self, c: u8) !void {
// log.warn("C0: {}", .{c});
switch (@intToEnum(ansi.C0, c)) {
.NUL => {},