From 10ec5f509ead6233795d81c6eecc0e77474322ff Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 31 Aug 2022 15:27:45 -0700 Subject: [PATCH] circbuf doesn't use zeroes, it takes a default value --- src/terminal/Screen2.zig | 2 +- src/terminal/circ_buf.zig | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/terminal/Screen2.zig b/src/terminal/Screen2.zig index 0556066b1..fa5826ee1 100644 --- a/src/terminal/Screen2.zig +++ b/src/terminal/Screen2.zig @@ -311,7 +311,7 @@ pub const RowIndexTag = enum { } }; -const StorageBuf = CircBuf(StorageCell); +const StorageBuf = CircBuf(StorageCell, .{ .cell = .{} }); /// The allocator used for all the storage operations alloc: Allocator, diff --git a/src/terminal/circ_buf.zig b/src/terminal/circ_buf.zig index 7f2c823f8..fd79d0dc3 100644 --- a/src/terminal/circ_buf.zig +++ b/src/terminal/circ_buf.zig @@ -3,7 +3,7 @@ const assert = std.debug.assert; const Allocator = std.mem.Allocator; /// Returns a circular buffer containing type T. -pub fn CircBuf(comptime T: type) type { +pub fn CircBuf(comptime T: type, comptime default: T) type { return struct { const Self = @This(); @@ -26,7 +26,7 @@ pub fn CircBuf(comptime T: type) type { /// Initialize a new circular buffer that can store size elements. pub fn init(alloc: Allocator, size: usize) !Self { var buf = try alloc.alloc(T, size); - std.mem.set(T, buf, std.mem.zeroes(T)); + std.mem.set(T, buf, default); return Self{ .storage = buf, @@ -141,7 +141,7 @@ test { const testing = std.testing; const alloc = testing.allocator; - const Buf = CircBuf(u8); + const Buf = CircBuf(u8, 0); var buf = try Buf.init(alloc, 12); defer buf.deinit(alloc); @@ -153,7 +153,7 @@ test "getPtrSlice fits" { const testing = std.testing; const alloc = testing.allocator; - const Buf = CircBuf(u8); + const Buf = CircBuf(u8, 0); var buf = try Buf.init(alloc, 12); defer buf.deinit(alloc); @@ -167,7 +167,7 @@ test "getPtrSlice wraps" { const testing = std.testing; const alloc = testing.allocator; - const Buf = CircBuf(u8); + const Buf = CircBuf(u8, 0); var buf = try Buf.init(alloc, 4); defer buf.deinit(alloc);