diff options
author | Martin Ashby <martin@ashbysoft.com> | 2023-09-28 10:54:58 +0100 |
---|---|---|
committer | Martin Ashby <martin@ashbysoft.com> | 2023-09-28 10:54:58 +0100 |
commit | 35494bc81b59165ee9264cd1004bb05a120279a3 (patch) | |
tree | 8d11946f8fc20e1f254301100e860f28bade5ee0 /src/proto/proto.zig | |
parent | 0c063d42430077881e563120ebfcf92c2cecf463 (diff) | |
download | pgz-35494bc81b59165ee9264cd1004bb05a120279a3.tar.gz pgz-35494bc81b59165ee9264cd1004bb05a120279a3.tar.bz2 pgz-35494bc81b59165ee9264cd1004bb05a120279a3.tar.xz pgz-35494bc81b59165ee9264cd1004bb05a120279a3.zip |
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.
Diffstat (limited to 'src/proto/proto.zig')
-rw-r--r-- | src/proto/proto.zig | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/proto/proto.zig b/src/proto/proto.zig index 5e4489d..9025347 100644 --- a/src/proto/proto.zig +++ b/src/proto/proto.zig @@ -51,13 +51,13 @@ pub fn read_message(allocator: std.mem.Allocator, stream_reader: anytype) !Backe const tag = try stream_reader.readByte(); const len = try stream_reader.readIntBig(u32); const buf = try allocator.alloc(u8, @as(u32, @intCast(len - 4))); - defer allocator.free(buf); try stream_reader.readNoEof(buf); inline for (@typeInfo(BackendMessage).Union.fields) |field| { if (field.type.Tag == tag) { return @unionInit(BackendMessage, field.name, try field.type.read(allocator, buf)); } } else { + allocator.free(buf); return ProtocolError.InvalidMessageType; } } |