Skip to content

Commit fe69332

Browse files
committed
std: use std.ArrayList(u8).OutStream instead of std.Buffer.OutStream
1 parent 9ab700b commit fe69332

File tree

5 files changed

+14
-15
lines changed

5 files changed

+14
-15
lines changed

doc/docgen.zig

+4-4
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
321321
var last_action = Action.Open;
322322
var last_columns: ?u8 = null;
323323

324-
var toc_buf = try std.Buffer.initSize(allocator, 0);
324+
var toc_buf = std.ArrayList(u8).init(allocator);
325325
defer toc_buf.deinit();
326326

327327
var toc = toc_buf.outStream();
@@ -607,7 +607,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
607607
}
608608

609609
fn urlize(allocator: *mem.Allocator, input: []const u8) ![]u8 {
610-
var buf = try std.Buffer.initSize(allocator, 0);
610+
var buf = std.ArrayList(u8).init(allocator);
611611
defer buf.deinit();
612612

613613
const out = buf.outStream();
@@ -626,7 +626,7 @@ fn urlize(allocator: *mem.Allocator, input: []const u8) ![]u8 {
626626
}
627627

628628
fn escapeHtml(allocator: *mem.Allocator, input: []const u8) ![]u8 {
629-
var buf = try std.Buffer.initSize(allocator, 0);
629+
var buf = std.ArrayList(u8).init(allocator);
630630
defer buf.deinit();
631631

632632
const out = buf.outStream();
@@ -672,7 +672,7 @@ test "term color" {
672672
}
673673

674674
fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 {
675-
var buf = try std.Buffer.initSize(allocator, 0);
675+
var buf = std.ArrayList(u8).init(allocator);
676676
defer buf.deinit();
677677

678678
var out = buf.outStream();

lib/std/zig/parser_test.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -2840,7 +2840,7 @@ fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *b
28402840
return error.ParseError;
28412841
}
28422842

2843-
var buffer = try std.Buffer.initSize(allocator, 0);
2843+
var buffer = std.ArrayList(u8).init(allocator);
28442844
errdefer buffer.deinit();
28452845

28462846
anything_changed.* = try std.zig.render(allocator, buffer.outStream(), tree);

src-self-hosted/errmsg.zig

+4-6
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,13 @@ pub const Msg = struct {
158158
parse_error: *const ast.Error,
159159
) !*Msg {
160160
const loc_token = parse_error.loc();
161-
var text_buf = try std.Buffer.initSize(comp.gpa(), 0);
161+
var text_buf = std.ArrayList(u8).init(comp.gpa());
162162
defer text_buf.deinit();
163163

164164
const realpath_copy = try mem.dupe(comp.gpa(), u8, tree_scope.root().realpath);
165165
errdefer comp.gpa().free(realpath_copy);
166166

167-
var out_stream = &std.io.BufferOutStream.init(&text_buf).stream;
168-
try parse_error.render(&tree_scope.tree.tokens, out_stream);
167+
try parse_error.render(&tree_scope.tree.tokens, text_buf.outStream());
169168

170169
const msg = try comp.gpa().create(Msg);
171170
msg.* = Msg{
@@ -198,14 +197,13 @@ pub const Msg = struct {
198197
realpath: []const u8,
199198
) !*Msg {
200199
const loc_token = parse_error.loc();
201-
var text_buf = try std.Buffer.initSize(allocator, 0);
200+
var text_buf = std.ArrayList(u8).init(allocator);
202201
defer text_buf.deinit();
203202

204203
const realpath_copy = try mem.dupe(allocator, u8, realpath);
205204
errdefer allocator.free(realpath_copy);
206205

207-
var out_stream = &std.io.BufferOutStream.init(&text_buf).stream;
208-
try parse_error.render(&tree.tokens, out_stream);
206+
try parse_error.render(&tree.tokens, text_buf.outStream());
209207

210208
const msg = try allocator.create(Msg);
211209
msg.* = Msg{

src-self-hosted/stage2.zig

+3-2
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,11 @@ fn printErrMsgToFile(
408408
const start_loc = tree.tokenLocationPtr(0, first_token);
409409
const end_loc = tree.tokenLocationPtr(first_token.end, last_token);
410410

411-
var text_buf = try std.Buffer.initSize(allocator, 0);
411+
var text_buf = std.ArrayList(u8).init(allocator);
412+
defer text_buf.deinit();
412413
const out_stream = &text_buf.outStream();
413414
try parse_error.render(&tree.tokens, out_stream);
414-
const text = text_buf.toOwnedSlice();
415+
const text = text_buf.span();
415416

416417
const stream = &file.outStream();
417418
try stream.print("{}:{}:{}: error: {}\n", .{ path, start_loc.line + 1, start_loc.column + 1, text });

src-self-hosted/type.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,10 @@ pub const Type = struct {
387387
};
388388
errdefer comp.gpa().destroy(self);
389389

390-
var name_buf = try std.Buffer.initSize(comp.gpa(), 0);
390+
var name_buf = std.ArrayList(u8).init(comp.gpa());
391391
defer name_buf.deinit();
392392

393-
const name_stream = &std.io.BufferOutStream.init(&name_buf).stream;
393+
const name_stream = name_buf.outStream();
394394

395395
switch (key.data) {
396396
.Generic => |generic| {

0 commit comments

Comments
 (0)