authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-02-09 20:15:51 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-02-09 20:15:51 -08:00
log9744f2b35f0d839d0bfddad241688c5b017951e8
tree43e2a1b200794f35d0696154041f8ef583422257
parent562fd5ffa90dd564f474d92285231e73213bef79

BufIndexer: don't use a fat pointer since we can verify the length is sufficient


1 files changed, 4 insertions(+), 3 deletions(-)

src/lib.zig+4-3
......@@ -387,20 +387,21 @@ pub fn indexBufferT(bytes: []const u8, comptime T: type, endian: std.builtin.End
387387
388388pub fn BufIndexer(comptime T: type, comptime endian: std.builtin.Endian) type {
389389 return struct {
390 bytes: []const u8,
390 bytes: [*]const u8,
391391 max_len: usize,
392392
393393 const Self = @This();
394394
395395 pub fn init(bytes: []const u8, max_len: usize) Self {
396 std.debug.assert(bytes.len >= @sizeOf(T) * max_len);
396397 return .{
397 .bytes = bytes,
398 .bytes = bytes.ptr,
398399 .max_len = max_len,
399400 };
400401 }
401402
402403 pub fn at(self: *const Self, idx: usize) T {
403 return indexBufferT(self.bytes, T, endian, idx, self.max_len);
404 return indexBufferT(self.bytes[0 .. @sizeOf(T) * self.max_len], T, endian, idx, self.max_len);
404405 }
405406 };
406407}