authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-05 02:17:53-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-05 02:17:53-07:00
log9292ded5a3b8c82ae731bb18d40c69b7e40177f8
tree154bceeaf82e3e96caab244932939dbc7e34a4d3
parente73257dec2d997e9d573419178695992790a9525

std.Io.Batch: fix add function

closes #31730 closes #31757

2 files changed, 7 insertions(+), 6 deletions(-)

lib/std/Io.zig+2-2
...@@ -500,8 +500,8 @@ pub const Batch = struct {...@@ -500,8 +500,8 @@ pub const Batch = struct {
500 /// Returns the index that will be returned by `next` after the operation completes.500 /// Returns the index that will be returned by `next` after the operation completes.
501 /// Asserts that no more than `storage.len` operations are active at a time.501 /// Asserts that no more than `storage.len` operations are active at a time.
502 pub fn add(batch: *Batch, operation: Operation) u32 {502 pub fn add(batch: *Batch, operation: Operation) u32 {
503 const index = batch.unused.next;503 const index = batch.unused.head.toIndex();
504 batch.addAt(index.toIndex(), operation);504 batch.addAt(index, operation);
505 return index;505 return index;
506 }506 }
507507
lib/std/Io/test.zig+5-4
...@@ -692,14 +692,15 @@ test "read from a file using Batch.awaitAsync API" {...@@ -692,14 +692,15 @@ test "read from a file using Batch.awaitAsync API" {
692 var storage: [2]Io.Operation.Storage = undefined;692 var storage: [2]Io.Operation.Storage = undefined;
693 var batch: Io.Batch = .init(&storage);693 var batch: Io.Batch = .init(&storage);
694694
695 batch.addAt(0, .{ .file_read_streaming = .{695 // Tests add API because this provides coverage for both add and addAt.
696 try testing.expectEqual(0, batch.add(.{ .file_read_streaming = .{
696 .file = eyes_file,697 .file = eyes_file,
697 .data = &.{&eyes_buf},698 .data = &.{&eyes_buf},
698 } });699 } }));
699 batch.addAt(1, .{ .file_read_streaming = .{700 try testing.expectEqual(1, batch.add(.{ .file_read_streaming = .{
700 .file = saviour_file,701 .file = saviour_file,
701 .data = &.{&saviour_buf},702 .data = &.{&saviour_buf},
702 } });703 } }));
703704
704 // This API is supposed to *always* work even if the target has no705 // This API is supposed to *always* work even if the target has no
705 // concurrency primitives available.706 // concurrency primitives available.