add std.LinearFifo.readableSliceOfLen

This commit is contained in:
Andrew Kelley
2023-03-14 19:47:42 -07:00
parent 6664d2418d
commit 4f1382e581

View File

@@ -164,6 +164,17 @@ pub fn LinearFifo(
return self.readableSliceMut(offset);
}
pub fn readableSliceOfLen(self: *Self, len: usize) []const T {
assert(len <= self.count);
const buf = self.readableSlice(0);
if (buf.len >= len) {
return buf[0..len];
} else {
self.realign();
return self.readableSlice(0)[0..len];
}
}
/// Discard first `count` items in the fifo
pub fn discard(self: *Self, count: usize) void {
assert(count <= self.count);