From 02fd62b415c99c72c245b0cf7a94b9245d29deb6 Mon Sep 17 00:00:00 2001 From: Dustin Date: Thu, 30 May 2024 17:41:02 -0600 Subject: [PATCH] Removed unnecessary allocation --- src/jetzig/http/Cookies.zig | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/jetzig/http/Cookies.zig b/src/jetzig/http/Cookies.zig index 6e31034..ae0b3ce 100644 --- a/src/jetzig/http/Cookies.zig +++ b/src/jetzig/http/Cookies.zig @@ -22,11 +22,14 @@ pub const CookieOptions = struct { /// Builds a cookie string pub fn allocPrint(self: CookieOptions, allocator: std.mem.Allocator, cookie_name: []const u8, cookie_value: []const u8) ![]const u8 { - var cookie_string = std.ArrayList(u8).init(allocator); // add cookie name, cookie value, path, and domain regardless of cookie options - const standard_components = try std.fmt.allocPrint(allocator, "{s}={s}; path={s}; domain={s};", .{ cookie_name, cookie_value, self.path, self.domain }); - defer allocator.free(standard_components); - try cookie_string.appendSlice(standard_components); + const standard_components = try std.fmt.allocPrint(allocator, "{s}={s}; path={s}; domain={s};", .{ + cookie_name, + cookie_value, + self.path, + self.domain, + }); + var cookie_string = std.ArrayList(u8).fromOwnedSlice(allocator, standard_components); // secure is required if samesite is set to none var require_secure = false; var buf: [256]u8 = undefined;