From 35494bc81b59165ee9264cd1004bb05a120279a3 Mon Sep 17 00:00:00 2001 From: Martin Ashby Date: Thu, 28 Sep 2023 10:54:58 +0100 Subject: Reduce allocations, the message takes ownership of the bytes read from the stream and is responsible for deallocating, rather than copying them to their own storage. --- src/proto/error_response.zig | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/proto/error_response.zig') diff --git a/src/proto/error_response.zig b/src/proto/error_response.zig index dc75053..58ca06e 100644 --- a/src/proto/error_response.zig +++ b/src/proto/error_response.zig @@ -27,13 +27,13 @@ line: ?u32 = null, routine: ?[]const u8 = null, unknown_fields: HMByteString, -pub fn read(allocator: std.mem.Allocator, b: []const u8) !ErrorResponse { +pub fn read(allocator: std.mem.Allocator, buf: []const u8) !ErrorResponse { var res = ErrorResponse{ .severity = "", .code = "", .message = "", .unknown_fields = HMByteString.init(allocator), - .buf = try allocator.dupe(u8, b), + .buf = buf, }; errdefer res.deinit(allocator); var it = std.mem.splitScalar(u8, res.buf.?, 0); @@ -178,7 +178,6 @@ test "round trip" { try std.testing.expectEqual(Tag, tag); const len = try reader.readIntBig(u32); const buf = try allocator.alloc(u8, len - 4); - defer allocator.free(buf); try reader.readNoEof(buf); var sm2 = try ErrorResponse.read(allocator, buf); defer sm2.deinit(allocator); -- cgit v1.2.3-ZIG