From 57725cf3a490660bbcc6b436635d2e67d269c00a Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 1 Sep 2022 22:05:42 -0700 Subject: [PATCH] cache row iterator max value --- pkg/tracy/tracy.zig | 3 +++ src/terminal/Screen.zig | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pkg/tracy/tracy.zig b/pkg/tracy/tracy.zig index 1e7aa4d78..d9b243fe9 100644 --- a/pkg/tracy/tracy.zig +++ b/pkg/tracy/tracy.zig @@ -15,6 +15,9 @@ pub usingnamespace if (enabled) Impl else Noop; const Impl = struct { const c = @cImport({ + //uncomment to enable callstacks, very slow + //@cDefine("TRACY_CALLSTACK", ""); + @cDefine("TRACY_ENABLE", ""); @cInclude("TracyC.h"); }); diff --git a/src/terminal/Screen.zig b/src/terminal/Screen.zig index b52a46c8e..74993e15c 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -232,10 +232,11 @@ pub const Row = struct { pub const RowIterator = struct { screen: *Screen, tag: RowIndexTag, + max: usize, value: usize = 0, pub fn next(self: *RowIterator) ?Row { - if (self.value >= self.tag.maxLen(self.screen)) return null; + if (self.value >= self.max) return null; const idx = self.tag.index(self.value); const res = self.screen.getRow(idx); self.value += 1; @@ -436,7 +437,14 @@ pub fn getCellPtr(self: *Screen, tag: RowIndexTag, y: usize, x: usize) *Cell { /// from index zero of the given row index type. This can therefore iterate /// from row 0 of the active area, history, viewport, etc. pub fn rowIterator(self: *Screen, tag: RowIndexTag) RowIterator { - return .{ .screen = self, .tag = tag }; + const tracy = trace(@src()); + defer tracy.end(); + + return .{ + .screen = self, + .tag = tag, + .max = tag.maxLen(self), + }; } /// Returns the row at the given index. This row is writable, although @@ -783,6 +791,9 @@ fn selectionSlices(self: *Screen, sel_raw: Selection) struct { /// be truncated as they are shrunk. If they are grown, the new space is filled /// with zeros. pub fn resizeWithoutReflow(self: *Screen, rows: usize, cols: usize) !void { + const tracy = trace(@src()); + defer tracy.end(); + // Make a copy so we can access the old indexes. var old = self.*; errdefer self.* = old;