performance: use a comptime StaticStringMap for string comparison

This commit is contained in:
Pierre Tachoire
2026-02-24 15:18:25 +01:00
parent 71707b5aa7
commit 42df54869f

View File

@@ -215,33 +215,31 @@ fn getMarkTime(self: *const Performance, mark_name: []const u8) !f64 {
// `navigationStart` is an equivalent to 0. // `navigationStart` is an equivalent to 0.
// Others are dependant to request arrival, end of request etc, but we // Others are dependant to request arrival, end of request etc, but we
// return a dummy 0 value for now. // return a dummy 0 value for now.
const navigation_timing_marks = [_][]const u8{ const navigation_timing_marks = std.StaticStringMap(void).initComptime(.{
"navigationStart", .{ "navigationStart", {} },
"unloadEventStart", .{ "unloadEventStart", {} },
"unloadEventEnd", .{ "unloadEventEnd", {} },
"redirectStart", .{ "redirectStart", {} },
"redirectEnd", .{ "redirectEnd", {} },
"fetchStart", .{ "fetchStart", {} },
"domainLookupStart", .{ "domainLookupStart", {} },
"domainLookupEnd", .{ "domainLookupEnd", {} },
"connectStart", .{ "connectStart", {} },
"connectEnd", .{ "connectEnd", {} },
"secureConnectionStart", .{ "secureConnectionStart", {} },
"requestStart", .{ "requestStart", {} },
"responseStart", .{ "responseStart", {} },
"responseEnd", .{ "responseEnd", {} },
"domLoading", .{ "domLoading", {} },
"domInteractive", .{ "domInteractive", {} },
"domContentLoadedEventStart", .{ "domContentLoadedEventStart", {} },
"domContentLoadedEventEnd", .{ "domContentLoadedEventEnd", {} },
"domComplete", .{ "domComplete", {} },
"loadEventStart", .{ "loadEventStart", {} },
"loadEventEnd", .{ "loadEventEnd", {} },
}; });
for (navigation_timing_marks) |name| { if (navigation_timing_marks.has(mark_name)) {
if (std.mem.eql(u8, name, mark_name)) { return 0;
return 0;
}
} }
return error.SyntaxError; // Mark not found return error.SyntaxError; // Mark not found