| ... | @@ -937,11 +937,11 @@ fn formatFloatValue(value: anytype, comptime fmt: []const u8, options: FormatOpt | ... | @@ -937,11 +937,11 @@ fn formatFloatValue(value: anytype, comptime fmt: []const u8, options: FormatOpt |
| 937 | } | 937 | } |
| 938 | | 938 | |
| 939 | pub fn allocPrint(allocator: std.mem.Allocator, comptime fmt: []const u8, args: anytype) ![]u8 { | 939 | pub fn allocPrint(allocator: std.mem.Allocator, comptime fmt: []const u8, args: anytype) ![]u8 { |
| 940 | const size = std.math.cast(usize, count(fmt, args)) orelse return error.OutOfMemory; | 940 | var aw: nio.AllocatingWriter = .init(allocator); |
| 941 | const buf = try allocator.alloc(u8, size); | 941 | errdefer aw.deinit(); |
| 942 | return bufPrint(buf, fmt, args) catch |err| switch (err) { | 942 | try aw.ensureUnusedCapacity(fmt.len); |
| 943 | error.NoSpaceLeft => unreachable, // we just counted the size above | 943 | try format(&aw, fmt, args); |
| 944 | }; | 944 | return aw.toOwnedSlice(); |
| 945 | } | 945 | } |
| 946 | pub fn allocPrintZ(allocator: std.mem.Allocator, comptime fmt: []const u8, args: anytype) ![:0]u8 { | 946 | pub fn allocPrintZ(allocator: std.mem.Allocator, comptime fmt: []const u8, args: anytype) ![:0]u8 { |
| 947 | const result = try allocPrint(allocator, fmt ++ "\x00", args); | 947 | const result = try allocPrint(allocator, fmt ++ "\x00", args); |