From 4ed6112e6db56e0f210a0356dbfc89828f5ed557 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 23 Oct 2023 12:18:23 -0700 Subject: [PATCH] move circular buffer to src/ --- src/{terminal => }/circ_buf.zig | 15 +-------------- src/main.zig | 1 + src/terminal/Screen.zig | 2 +- 3 files changed, 3 insertions(+), 15 deletions(-) rename src/{terminal => }/circ_buf.zig (98%) diff --git a/src/terminal/circ_buf.zig b/src/circ_buf.zig similarity index 98% rename from src/terminal/circ_buf.zig rename to src/circ_buf.zig index 63a0fa49d..484f4e6b0 100644 --- a/src/terminal/circ_buf.zig +++ b/src/circ_buf.zig @@ -1,8 +1,7 @@ const std = @import("std"); const assert = std.debug.assert; const Allocator = std.mem.Allocator; -const trace = @import("tracy").trace; -const fastmem = @import("../fastmem.zig"); +const fastmem = @import("fastmem.zig"); /// Returns a circular buffer containing type T. pub fn CircBuf(comptime T: type, comptime default: T) type { @@ -95,9 +94,6 @@ pub fn CircBuf(comptime T: type, comptime default: T) type { /// Resize the buffer to the given size (larger or smaller). /// If larger, new values will be set to the default value. pub fn resize(self: *Self, alloc: Allocator, size: usize) !void { - const tracy = trace(@src()); - defer tracy.end(); - // Rotate to zero so it is aligned. try self.rotateToZero(alloc); @@ -121,9 +117,6 @@ pub fn CircBuf(comptime T: type, comptime default: T) type { /// Rotate the data so that it is zero-aligned. fn rotateToZero(self: *Self, alloc: Allocator) !void { - const tracy = trace(@src()); - defer tracy.end(); - // TODO: this does this in the worst possible way by allocating. // rewrite to not allocate, its possible, I'm just lazy right now. @@ -171,9 +164,6 @@ pub fn CircBuf(comptime T: type, comptime default: T) type { pub fn deleteOldest(self: *Self, n: usize) void { assert(n <= self.storage.len); - const tracy = trace(@src()); - defer tracy.end(); - // Clear the values back to default const slices = self.getPtrSlice(0, n); inline for (slices) |slice| @memset(slice, default); @@ -190,9 +180,6 @@ 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 { - const tracy = trace(@src()); - defer tracy.end(); - // Note: this assertion is very important, it hints the compiler // which generates ~10% faster code than without it. assert(offset + slice_len <= self.capacity()); diff --git a/src/main.zig b/src/main.zig index b697b05c1..4eadcefad 100644 --- a/src/main.zig +++ b/src/main.zig @@ -283,6 +283,7 @@ pub const GlobalState = struct { } }; test { + _ = @import("circ_buf.zig"); _ = @import("Pty.zig"); _ = @import("Command.zig"); _ = @import("font/main.zig"); diff --git a/src/terminal/Screen.zig b/src/terminal/Screen.zig index e349f6b90..0a3c524ee 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -62,7 +62,7 @@ const sgr = @import("sgr.zig"); const color = @import("color.zig"); const kitty = @import("kitty.zig"); const point = @import("point.zig"); -const CircBuf = @import("circ_buf.zig").CircBuf; +const CircBuf = @import("../circ_buf.zig").CircBuf; const Selection = @import("Selection.zig"); const fastmem = @import("../fastmem.zig"); const charsets = @import("charsets.zig");