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;...@@ -3,7 +3,6 @@ const builtin = std.builtin;
3const os = std.os;3const os = std.os;
4const fs = std.fs;4const fs = std.fs;
5const BufMap = std.BufMap;5const BufMap = std.BufMap;
6const Buffer = std.Buffer;
7const mem = std.mem;6const mem = std.mem;
8const math = std.math;7const math = std.math;
9const Allocator = mem.Allocator;8const Allocator = mem.Allocator;
...@@ -266,7 +265,7 @@ pub const ArgIteratorWindows = struct {...@@ -266,7 +265,7 @@ pub const ArgIteratorWindows = struct {
266 }265 }
267266
268 fn internalNext(self: *ArgIteratorWindows, allocator: *Allocator) NextError![]u8 {267 fn internalNext(self: *ArgIteratorWindows, allocator: *Allocator) NextError![]u8 {
269 var buf = try Buffer.initSize(allocator, 0);268 var buf = std.ArrayList(u8).init(allocator);
270 defer buf.deinit();269 defer buf.deinit();
271270
272 var backslash_count: usize = 0;271 var backslash_count: usize = 0;
...@@ -282,10 +281,10 @@ pub const ArgIteratorWindows = struct {...@@ -282,10 +281,10 @@ pub const ArgIteratorWindows = struct {
282 if (quote_is_real) {281 if (quote_is_real) {
283 self.seen_quote_count += 1;282 self.seen_quote_count += 1;
284 if (self.seen_quote_count == self.quote_count and self.seen_quote_count % 2 == 1) {283 if (self.seen_quote_count == self.quote_count and self.seen_quote_count % 2 == 1) {
285 try buf.appendByte('"');284 try buf.append('"');
286 }285 }
287 } else {286 } else {
288 try buf.appendByte('"');287 try buf.append('"');
289 }288 }
290 },289 },
291 '\\' => {290 '\\' => {
...@@ -295,7 +294,7 @@ pub const ArgIteratorWindows = struct {...@@ -295,7 +294,7 @@ pub const ArgIteratorWindows = struct {
295 try self.emitBackslashes(&buf, backslash_count);294 try self.emitBackslashes(&buf, backslash_count);
296 backslash_count = 0;295 backslash_count = 0;
297 if (self.seen_quote_count % 2 == 1 and self.seen_quote_count != self.quote_count) {296 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);
299 } else {298 } else {
300 return buf.toOwnedSlice();299 return buf.toOwnedSlice();
301 }300 }
...@@ -303,16 +302,16 @@ pub const ArgIteratorWindows = struct {...@@ -303,16 +302,16 @@ pub const ArgIteratorWindows = struct {
303 else => {302 else => {
304 try self.emitBackslashes(&buf, backslash_count);303 try self.emitBackslashes(&buf, backslash_count);
305 backslash_count = 0;304 backslash_count = 0;
306 try buf.appendByte(byte);305 try buf.append(byte);
307 },306 },
308 }307 }
309 }308 }
310 }309 }
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 {
313 var i: usize = 0;312 var i: usize = 0;
314 while (i < emit_count) : (i += 1) {313 while (i < emit_count) : (i += 1) {
315 try buf.appendByte('\\');314 try buf.append('\\');
316 }315 }
317 }316 }
318317
...@@ -410,7 +409,7 @@ pub fn argsAlloc(allocator: *mem.Allocator) ![][]u8 {...@@ -410,7 +409,7 @@ pub fn argsAlloc(allocator: *mem.Allocator) ![][]u8 {
410409
411 // TODO refactor to only make 1 allocation.410 // TODO refactor to only make 1 allocation.
412 var it = args();411 var it = args();
413 var contents = try Buffer.initSize(allocator, 0);412 var contents = std.ArrayList(u8).init(allocator);
414 defer contents.deinit();413 defer contents.deinit();
415414
416 var slice_list = std.ArrayList(usize).init(allocator);415 var slice_list = std.ArrayList(usize).init(allocator);
...@@ -419,7 +418,7 @@ pub fn argsAlloc(allocator: *mem.Allocator) ![][]u8 {...@@ -419,7 +418,7 @@ pub fn argsAlloc(allocator: *mem.Allocator) ![][]u8 {
419 while (it.next(allocator)) |arg_or_err| {418 while (it.next(allocator)) |arg_or_err| {
420 const arg = try arg_or_err;419 const arg = try arg_or_err;
421 defer allocator.free(arg);420 defer allocator.free(arg);
422 try contents.append(arg);421 try contents.appendSlice(arg);
423 try slice_list.append(arg.len);422 try slice_list.append(arg.len);
424 }423 }
425424