From 37e6a64690a257b4f5a9e3f234deb8b72e74ca54 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Sat, 7 Mar 2020 15:42:10 +1100 Subject: [PATCH] std: use Buffer.outStream in std/child_process.zig --- lib/std/child_process.zig | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/std/child_process.zig b/lib/std/child_process.zig index 3013133b11..8e341a07b8 100644 --- a/lib/std/child_process.zig +++ b/lib/std/child_process.zig @@ -758,37 +758,36 @@ fn windowsCreateProcess(app_name: [*:0]u16, cmd_line: [*:0]u16, envp_ptr: ?[*]u1 /// Caller must dealloc. /// Guarantees a null byte at result[result.len]. -fn windowsCreateCommandLine(allocator: *mem.Allocator, argv: []const []const u8) ![]u8 { +fn windowsCreateCommandLine(allocator: *mem.Allocator, argv: []const []const u8) ![:0]u8 { var buf = try Buffer.initSize(allocator, 0); defer buf.deinit(); - - var buf_stream = buf.outStream(); + const buf_stream = buf.outStream(); for (argv) |arg, arg_i| { - if (arg_i != 0) try buf.appendByte(' '); + if (arg_i != 0) try buf_stream.writeByte(' '); if (mem.indexOfAny(u8, arg, " \t\n\"") == null) { - try buf.append(arg); + try buf_stream.writeAll(arg); continue; } - try buf.appendByte('"'); + try buf_stream.writeByte('"'); var backslash_count: usize = 0; for (arg) |byte| { switch (byte) { '\\' => backslash_count += 1, '"' => { try buf_stream.writeByteNTimes('\\', backslash_count * 2 + 1); - try buf.appendByte('"'); + try buf_stream.writeByte('"'); backslash_count = 0; }, else => { try buf_stream.writeByteNTimes('\\', backslash_count); - try buf.appendByte(byte); + try buf_stream.writeByte(byte); backslash_count = 0; }, } } try buf_stream.writeByteNTimes('\\', backslash_count * 2); - try buf.appendByte('"'); + try buf_stream.writeByte('"'); } return buf.toOwnedSlice();