From 8a18a0258fd8639bc179af6845330f162d099840 Mon Sep 17 00:00:00 2001 From: Rene Schallner Date: Sat, 24 Feb 2024 15:36:44 +0100 Subject: [PATCH] performance: revert r.method enum back to ?[]const u8 new http.Method enum is available via r.methodAsEnum() --- examples/hello2/hello2.zig | 5 +++-- src/request.zig | 7 +++++-- src/zap.zig | 9 +++------ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/examples/hello2/hello2.zig b/examples/hello2/hello2.zig index 52c70ec..4f43a5e 100644 --- a/examples/hello2/hello2.zig +++ b/examples/hello2/hello2.zig @@ -2,7 +2,8 @@ const std = @import("std"); const zap = @import("zap"); fn on_request(r: zap.Request) void { - const m = r.method_str orelse ""; + const m = r.methodAsEnum(); + const m_str = r.method orelse ""; const p = r.path orelse "/"; const qm = if (r.query) |_| "?" else ""; const qq = r.query orelse ""; @@ -13,7 +14,7 @@ fn on_request(r: zap.Request) void { } else { std.debug.print(">> Special Header: \n", .{}); } - std.debug.print(">> {s} {s}{s}{s}\n", .{ m, p, qm, qq }); + std.debug.print(">> {s}({}) {s}{s}{s}\n", .{ m_str, m, p, qm, qq }); if (r.body) |the_body| { std.debug.print(">> BODY: {s}\n", .{the_body}); diff --git a/src/request.zig b/src/request.zig index 44afbef..75a3be7 100644 --- a/src/request.zig +++ b/src/request.zig @@ -266,8 +266,7 @@ pub const CookieArgs = struct { path: ?[]const u8, query: ?[]const u8, body: ?[]const u8, -method: http.Method, -method_str: ?[]const u8, +method: ?[]const u8, h: [*c]fio.http_s, /// NEVER touch this field!!!! @@ -792,3 +791,7 @@ pub fn getParamSlices(self: *const Self) ParamSliceIterator { const query = self.query orelse ""; return ParamSliceIterator.init(query); } + +pub fn methodAsEnum(self: *const Self) http.Method { + return http.methodToEnum(self.method); +} diff --git a/src/zap.zig b/src/zap.zig index 8ab0de7..0414d68 100644 --- a/src/zap.zig +++ b/src/zap.zig @@ -207,8 +207,7 @@ pub const HttpListener = struct { .path = util.fio2str(r.*.path), .query = util.fio2str(r.*.query), .body = util.fio2str(r.*.body), - .method = http.methodToEnum(util.fio2str(r.*.method)), - .method_str = util.fio2str(r.*.method), + .method = util.fio2str(r.*.method), .h = r, ._is_finished_request_global = false, ._user_context = undefined, @@ -234,8 +233,7 @@ pub const HttpListener = struct { .path = util.fio2str(r.*.path), .query = util.fio2str(r.*.query), .body = util.fio2str(r.*.body), - .method = http.methodToEnum(util.fio2str(r.*.method)), - .method_str = util.fio2str(r.*.method), + .method = util.fio2str(r.*.method), .h = r, ._is_finished_request_global = false, ._user_context = undefined, @@ -256,8 +254,7 @@ pub const HttpListener = struct { .path = util.fio2str(r.*.path), .query = util.fio2str(r.*.query), .body = util.fio2str(r.*.body), - .method = http.methodToEnum(util.fio2str(r.*.method)), - .method_str = util.fio2str(r.*.method), + .method = util.fio2str(r.*.method), .h = r, ._is_finished_request_global = false, ._user_context = undefined,