Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions lib/compiler/resinator/cvtres.zig
Original file line number Diff line number Diff line change
Expand Up @@ -665,19 +665,16 @@ const ResourceTree = struct {
pub fn writeCoff(
self: *const ResourceTree,
allocator: Allocator,
writer: anytype,
w: anytype,
resources_in_data_order: []const Resource,
lengths: Lengths,
coff_string_table: *StringTable,
) ![]const std.coff.Symbol {
if (self.type_to_name_map.count() == 0) {
try writer.writeByteNTimes(0, 16);
try w.writeByteNTimes(0, 16);
return &.{};
}

var counting_writer = std.io.countingWriter(writer);
const w = counting_writer.writer();

var level2_list: std.ArrayListUnmanaged(*const NameToLanguageMap) = .empty;
defer level2_list.deinit(allocator);

Expand Down Expand Up @@ -735,7 +732,6 @@ const ResourceTree = struct {
try level2_list.append(allocator, name_to_lang_map);
}
}
std.debug.assert(counting_writer.bytes_written == level2_start);

const level3_start = level2_start + lengths.level2;
var level3_address = level3_start;
Expand Down Expand Up @@ -771,7 +767,6 @@ const ResourceTree = struct {
try level3_list.append(allocator, lang_to_resources_map);
}
}
std.debug.assert(counting_writer.bytes_written == level3_start);

var reloc_addresses = try allocator.alloc(u32, resources_in_data_order.len);
defer allocator.free(reloc_addresses);
Expand Down Expand Up @@ -813,7 +808,6 @@ const ResourceTree = struct {
try resources_list.append(allocator, reloc_resource);
}
}
std.debug.assert(counting_writer.bytes_written == data_entries_start);

for (resources_list.items, 0..) |reloc_resource, i| {
// TODO: This logic works but is convoluted, would be good to clean this up
Expand All @@ -827,7 +821,6 @@ const ResourceTree = struct {
};
try w.writeStructEndian(data_entry, .little);
}
std.debug.assert(counting_writer.bytes_written == strings_start);

for (self.rsrc_string_table.keys()) |v| {
const str = v.name;
Expand Down
5 changes: 0 additions & 5 deletions lib/std/Io.zig
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,6 @@ pub const FixedBufferStream = @import("Io/fixed_buffer_stream.zig").FixedBufferS
/// Deprecated in favor of `Reader`.
pub const fixedBufferStream = @import("Io/fixed_buffer_stream.zig").fixedBufferStream;
/// Deprecated with no replacement; inefficient pattern
pub const CountingWriter = @import("Io/counting_writer.zig").CountingWriter;
/// Deprecated with no replacement; inefficient pattern
pub const countingWriter = @import("Io/counting_writer.zig").countingWriter;
/// Deprecated with no replacement; inefficient pattern
pub const CountingReader = @import("Io/counting_reader.zig").CountingReader;
/// Deprecated with no replacement; inefficient pattern
pub const countingReader = @import("Io/counting_reader.zig").countingReader;
Expand Down Expand Up @@ -917,7 +913,6 @@ test {
_ = Reader;
_ = Writer;
_ = BufferedWriter;
_ = CountingWriter;
_ = CountingReader;
_ = FixedBufferStream;
_ = tty;
Expand Down
5 changes: 5 additions & 0 deletions lib/std/Io/Writer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2239,6 +2239,11 @@ pub const Discarding = struct {
};
}

/// Includes buffered data (no need to flush).
pub fn fullCount(d: *const Discarding) u64 {
return d.count + d.writer.end;
}

pub fn drain(w: *Writer, data: []const []const u8, splat: usize) Error!usize {
const d: *Discarding = @alignCast(@fieldParentPtr("writer", w));
const slice = data[0 .. data.len - 1];
Expand Down
39 changes: 0 additions & 39 deletions lib/std/Io/counting_writer.zig

This file was deleted.

16 changes: 9 additions & 7 deletions lib/std/crypto/phc_encoding.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const fmt = std.fmt;
const io = std.io;
const mem = std.mem;
const meta = std.meta;
const Writer = std.Io.Writer;

const fields_delimiter = "$";
const fields_delimiter_scalar = '$';
Expand Down Expand Up @@ -188,19 +189,20 @@ pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult
///
/// `params` can also include any additional parameters.
pub fn serialize(params: anytype, str: []u8) Error![]const u8 {
var buf = io.fixedBufferStream(str);
try serializeTo(params, buf.writer());
return buf.getWritten();
var w: Writer = .fixed(str);
serializeTo(params, &w) catch return error.NoSpaceLeft;
return w.buffered();
}

/// Compute the number of bytes required to serialize `params`
pub fn calcSize(params: anytype) usize {
var buf = io.countingWriter(io.null_writer);
serializeTo(params, buf.writer()) catch unreachable;
return @as(usize, @intCast(buf.bytes_written));
var trash: [128]u8 = undefined;
var d: Writer.Discarding = .init(&trash);
serializeTo(params, &d.writer) catch unreachable;
return @intCast(d.fullCount());
}

fn serializeTo(params: anytype, out: anytype) !void {
fn serializeTo(params: anytype, out: *std.Io.Writer) !void {
const HashResult = @TypeOf(params);

if (@hasField(HashResult, version_param_name)) {
Expand Down
7 changes: 4 additions & 3 deletions lib/std/crypto/scrypt.zig
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,10 @@ const crypt_format = struct {

/// Compute the number of bytes required to serialize `params`
pub fn calcSize(params: anytype) usize {
var buf = io.countingWriter(io.null_writer);
serializeTo(params, buf.writer()) catch unreachable;
return @as(usize, @intCast(buf.bytes_written));
var trash: [128]u8 = undefined;
var d: std.Io.Writer.Discarding = .init(&trash);
serializeTo(params, &d) catch unreachable;
return @intCast(d.fullCount());
}

fn serializeTo(params: anytype, out: anytype) !void {
Expand Down
7 changes: 3 additions & 4 deletions src/arch/x86_64/encoder.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1204,11 +1204,10 @@ const TestEncode = struct {
mnemonic: Instruction.Mnemonic,
ops: []const Instruction.Operand,
) !void {
var stream = std.io.fixedBufferStream(&enc.buffer);
var count_writer = std.io.countingWriter(stream.writer());
var writer: std.Io.Writer = .fixed(&enc.buffer);
const inst: Instruction = try .new(.none, mnemonic, ops);
try inst.encode(count_writer.writer(), .{});
enc.index = count_writer.bytes_written;
try inst.encode(&writer, .{});
enc.index = writer.bufferedLen();
}

fn code(enc: TestEncode) []const u8 {
Expand Down
Loading