authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-02-11 23:01:30+11:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-06 18:49:12-05:00
log5c0d6ef5ec0fa31da15be1fd579c9f70e4cef7dd
treefe64faea5261742199a5a969d3842bef20e3e471
parentd136c795affe9d3a7522eefe3ccc098a52434de0
signaturelock-open Commit is signed but in an unrecognized format.

std: use ArrayList instead of Buffer from std/process.zig


1 files changed, 9 insertions(+), 10 deletions(-)

lib/std/process.zig+9-10
......@@ -3,7 +3,6 @@ const builtin = std.builtin;
33const os = std.os;
44const fs = std.fs;
55const BufMap = std.BufMap;
6const Buffer = std.Buffer;
76const mem = std.mem;
87const math = std.math;
98const Allocator = mem.Allocator;
......@@ -266,7 +265,7 @@ pub const ArgIteratorWindows = struct {
266265 }
267266
268267 fn internalNext(self: *ArgIteratorWindows, allocator: *Allocator) NextError![]u8 {
269 var buf = try Buffer.initSize(allocator, 0);
268 var buf = std.ArrayList(u8).init(allocator);
270269 defer buf.deinit();
271270
272271 var backslash_count: usize = 0;
......@@ -282,10 +281,10 @@ pub const ArgIteratorWindows = struct {
282281 if (quote_is_real) {
283282 self.seen_quote_count += 1;
284283 if (self.seen_quote_count == self.quote_count and self.seen_quote_count % 2 == 1) {
285 try buf.appendByte('"');
284 try buf.append('"');
286285 }
287286 } else {
288 try buf.appendByte('"');
287 try buf.append('"');
289288 }
290289 },
291290 '\\' => {
......@@ -295,7 +294,7 @@ pub const ArgIteratorWindows = struct {
295294 try self.emitBackslashes(&buf, backslash_count);
296295 backslash_count = 0;
297296 if (self.seen_quote_count % 2 == 1 and self.seen_quote_count != self.quote_count) {
298 try buf.appendByte(byte);
297 try buf.append(byte);
299298 } else {
300299 return buf.toOwnedSlice();
301300 }
......@@ -303,16 +302,16 @@ pub const ArgIteratorWindows = struct {
303302 else => {
304303 try self.emitBackslashes(&buf, backslash_count);
305304 backslash_count = 0;
306 try buf.appendByte(byte);
305 try buf.append(byte);
307306 },
308307 }
309308 }
310309 }
311310
312 fn emitBackslashes(self: *ArgIteratorWindows, buf: *Buffer, emit_count: usize) !void {
311 fn emitBackslashes(self: *ArgIteratorWindows, buf: *std.ArrayList(u8), emit_count: usize) !void {
313312 var i: usize = 0;
314313 while (i < emit_count) : (i += 1) {
315 try buf.appendByte('\\');
314 try buf.append('\\');
316315 }
317316 }
318317
......@@ -410,7 +409,7 @@ pub fn argsAlloc(allocator: *mem.Allocator) ![][]u8 {
410409
411410 // TODO refactor to only make 1 allocation.
412411 var it = args();
413 var contents = try Buffer.initSize(allocator, 0);
412 var contents = std.ArrayList(u8).init(allocator);
414413 defer contents.deinit();
415414
416415 var slice_list = std.ArrayList(usize).init(allocator);
......@@ -419,7 +418,7 @@ pub fn argsAlloc(allocator: *mem.Allocator) ![][]u8 {
419418 while (it.next(allocator)) |arg_or_err| {
420419 const arg = try arg_or_err;
421420 defer allocator.free(arg);
422 try contents.append(arg);
421 try contents.appendSlice(arg);
423422 try slice_list.append(arg.len);
424423 }
425424