move circular buffer to src/

This commit is contained in:
Mitchell Hashimoto
2023-10-23 12:18:23 -07:00
parent 41dbbf43d2
commit 4ed6112e6d
3 changed files with 3 additions and 15 deletions

View File

@ -1,8 +1,7 @@
const std = @import("std"); const std = @import("std");
const assert = std.debug.assert; const assert = std.debug.assert;
const Allocator = std.mem.Allocator; 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. /// Returns a circular buffer containing type T.
pub fn CircBuf(comptime T: type, comptime default: T) type { 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). /// Resize the buffer to the given size (larger or smaller).
/// If larger, new values will be set to the default value. /// If larger, new values will be set to the default value.
pub fn resize(self: *Self, alloc: Allocator, size: usize) !void { pub fn resize(self: *Self, alloc: Allocator, size: usize) !void {
const tracy = trace(@src());
defer tracy.end();
// Rotate to zero so it is aligned. // Rotate to zero so it is aligned.
try self.rotateToZero(alloc); 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. /// Rotate the data so that it is zero-aligned.
fn rotateToZero(self: *Self, alloc: Allocator) !void { 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. // TODO: this does this in the worst possible way by allocating.
// rewrite to not allocate, its possible, I'm just lazy right now. // 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 { pub fn deleteOldest(self: *Self, n: usize) void {
assert(n <= self.storage.len); assert(n <= self.storage.len);
const tracy = trace(@src());
defer tracy.end();
// Clear the values back to default // Clear the values back to default
const slices = self.getPtrSlice(0, n); const slices = self.getPtrSlice(0, n);
inline for (slices) |slice| @memset(slice, default); 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 end of our buffer. This never "rotates" the buffer because
/// the offset can only be within the size of the buffer. /// the offset can only be within the size of the buffer.
pub fn getPtrSlice(self: *Self, offset: usize, slice_len: usize) [2][]T { 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 // Note: this assertion is very important, it hints the compiler
// which generates ~10% faster code than without it. // which generates ~10% faster code than without it.
assert(offset + slice_len <= self.capacity()); assert(offset + slice_len <= self.capacity());

View File

@ -283,6 +283,7 @@ pub const GlobalState = struct {
} }
}; };
test { test {
_ = @import("circ_buf.zig");
_ = @import("Pty.zig"); _ = @import("Pty.zig");
_ = @import("Command.zig"); _ = @import("Command.zig");
_ = @import("font/main.zig"); _ = @import("font/main.zig");

View File

@ -62,7 +62,7 @@ const sgr = @import("sgr.zig");
const color = @import("color.zig"); const color = @import("color.zig");
const kitty = @import("kitty.zig"); const kitty = @import("kitty.zig");
const point = @import("point.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 Selection = @import("Selection.zig");
const fastmem = @import("../fastmem.zig"); const fastmem = @import("../fastmem.zig");
const charsets = @import("charsets.zig"); const charsets = @import("charsets.zig");