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

master
daurnimator 2020-02-11 23:01:30 +11:00 committed by Andrew Kelley
parent d136c795af
commit 5c0d6ef5ec
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
1 changed files with 9 additions and 10 deletions

View File

@ -3,7 +3,6 @@ const builtin = std.builtin;
const os = std.os; const os = std.os;
const fs = std.fs; const fs = std.fs;
const BufMap = std.BufMap; const BufMap = std.BufMap;
const Buffer = std.Buffer;
const mem = std.mem; const mem = std.mem;
const math = std.math; const math = std.math;
const Allocator = mem.Allocator; const Allocator = mem.Allocator;
@ -266,7 +265,7 @@ pub const ArgIteratorWindows = struct {
} }
fn internalNext(self: *ArgIteratorWindows, allocator: *Allocator) NextError![]u8 { fn internalNext(self: *ArgIteratorWindows, allocator: *Allocator) NextError![]u8 {
var buf = try Buffer.initSize(allocator, 0); var buf = std.ArrayList(u8).init(allocator);
defer buf.deinit(); defer buf.deinit();
var backslash_count: usize = 0; var backslash_count: usize = 0;
@ -282,10 +281,10 @@ pub const ArgIteratorWindows = struct {
if (quote_is_real) { if (quote_is_real) {
self.seen_quote_count += 1; self.seen_quote_count += 1;
if (self.seen_quote_count == self.quote_count and self.seen_quote_count % 2 == 1) { if (self.seen_quote_count == self.quote_count and self.seen_quote_count % 2 == 1) {
try buf.appendByte('"'); try buf.append('"');
} }
} else { } else {
try buf.appendByte('"'); try buf.append('"');
} }
}, },
'\\' => { '\\' => {
@ -295,7 +294,7 @@ pub const ArgIteratorWindows = struct {
try self.emitBackslashes(&buf, backslash_count); try self.emitBackslashes(&buf, backslash_count);
backslash_count = 0; backslash_count = 0;
if (self.seen_quote_count % 2 == 1 and self.seen_quote_count != self.quote_count) { if (self.seen_quote_count % 2 == 1 and self.seen_quote_count != self.quote_count) {
try buf.appendByte(byte); try buf.append(byte);
} else { } else {
return buf.toOwnedSlice(); return buf.toOwnedSlice();
} }
@ -303,16 +302,16 @@ pub const ArgIteratorWindows = struct {
else => { else => {
try self.emitBackslashes(&buf, backslash_count); try self.emitBackslashes(&buf, backslash_count);
backslash_count = 0; backslash_count = 0;
try buf.appendByte(byte); try buf.append(byte);
}, },
} }
} }
} }
fn emitBackslashes(self: *ArgIteratorWindows, buf: *Buffer, emit_count: usize) !void { fn emitBackslashes(self: *ArgIteratorWindows, buf: *std.ArrayList(u8), emit_count: usize) !void {
var i: usize = 0; var i: usize = 0;
while (i < emit_count) : (i += 1) { while (i < emit_count) : (i += 1) {
try buf.appendByte('\\'); try buf.append('\\');
} }
} }
@ -410,7 +409,7 @@ pub fn argsAlloc(allocator: *mem.Allocator) ![][]u8 {
// TODO refactor to only make 1 allocation. // TODO refactor to only make 1 allocation.
var it = args(); var it = args();
var contents = try Buffer.initSize(allocator, 0); var contents = std.ArrayList(u8).init(allocator);
defer contents.deinit(); defer contents.deinit();
var slice_list = std.ArrayList(usize).init(allocator); var slice_list = std.ArrayList(usize).init(allocator);
@ -419,7 +418,7 @@ pub fn argsAlloc(allocator: *mem.Allocator) ![][]u8 {
while (it.next(allocator)) |arg_or_err| { while (it.next(allocator)) |arg_or_err| {
const arg = try arg_or_err; const arg = try arg_or_err;
defer allocator.free(arg); defer allocator.free(arg);
try contents.append(arg); try contents.appendSlice(arg);
try slice_list.append(arg.len); try slice_list.append(arg.len);
} }