mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
std.fifo.LinearFifo: ensureUnusedCapacity and ensureTotalCapacity
Same as c8ae581fef6506a8234cdba1355ba7f0f449031a, but for LinearFifo.
This commit is contained in:
parent
d2b5105f54
commit
cfe71cb67a
@ -119,8 +119,11 @@ pub fn LinearFifo(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`.
|
||||||
|
pub const ensureCapacity = ensureTotalCapacity;
|
||||||
|
|
||||||
/// Ensure that the buffer can fit at least `size` items
|
/// Ensure that the buffer can fit at least `size` items
|
||||||
pub fn ensureCapacity(self: *Self, size: usize) !void {
|
pub fn ensureTotalCapacity(self: *Self, size: usize) !void {
|
||||||
if (self.buf.len >= size) return;
|
if (self.buf.len >= size) return;
|
||||||
if (buffer_type == .Dynamic) {
|
if (buffer_type == .Dynamic) {
|
||||||
self.realign();
|
self.realign();
|
||||||
@ -135,7 +138,7 @@ pub fn LinearFifo(
|
|||||||
pub fn ensureUnusedCapacity(self: *Self, size: usize) error{OutOfMemory}!void {
|
pub fn ensureUnusedCapacity(self: *Self, size: usize) error{OutOfMemory}!void {
|
||||||
if (self.writableLength() >= size) return;
|
if (self.writableLength() >= size) return;
|
||||||
|
|
||||||
return try self.ensureCapacity(math.add(usize, self.count, size) catch return error.OutOfMemory);
|
return try self.ensureTotalCapacity(math.add(usize, self.count, size) catch return error.OutOfMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns number of items currently in fifo
|
/// Returns number of items currently in fifo
|
||||||
@ -471,7 +474,7 @@ test "LinearFifo(u8, .Dynamic)" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
try fifo.ensureCapacity(1);
|
try fifo.ensureTotalCapacity(1);
|
||||||
var in_fbs = std.io.fixedBufferStream("pump test");
|
var in_fbs = std.io.fixedBufferStream("pump test");
|
||||||
var out_buf: [50]u8 = undefined;
|
var out_buf: [50]u8 = undefined;
|
||||||
var out_fbs = std.io.fixedBufferStream(&out_buf);
|
var out_fbs = std.io.fixedBufferStream(&out_buf);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user