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.
// Others are dependant to request arrival, end of request etc, but we
// return a dummy 0 value for now.
const navigation_timing_marks = [_][]const u8{
"navigationStart",
"unloadEventStart",
"unloadEventEnd",
"redirectStart",
"redirectEnd",
"fetchStart",
"domainLookupStart",
"domainLookupEnd",
"connectStart",
"connectEnd",
"secureConnectionStart",
"requestStart",
"responseStart",
"responseEnd",
"domLoading",
"domInteractive",
"domContentLoadedEventStart",
"domContentLoadedEventEnd",
"domComplete",
"loadEventStart",
"loadEventEnd",
};
for (navigation_timing_marks) |name| {
if (std.mem.eql(u8, name, mark_name)) {
return 0;
}
const navigation_timing_marks = std.StaticStringMap(void).initComptime(.{
.{ "navigationStart", {} },
.{ "unloadEventStart", {} },
.{ "unloadEventEnd", {} },
.{ "redirectStart", {} },
.{ "redirectEnd", {} },
.{ "fetchStart", {} },
.{ "domainLookupStart", {} },
.{ "domainLookupEnd", {} },
.{ "connectStart", {} },
.{ "connectEnd", {} },
.{ "secureConnectionStart", {} },
.{ "requestStart", {} },
.{ "responseStart", {} },
.{ "responseEnd", {} },
.{ "domLoading", {} },
.{ "domInteractive", {} },
.{ "domContentLoadedEventStart", {} },
.{ "domContentLoadedEventEnd", {} },
.{ "domComplete", {} },
.{ "loadEventStart", {} },
.{ "loadEventEnd", {} },
});
if (navigation_timing_marks.has(mark_name)) {
return 0;
}
return error.SyntaxError; // Mark not found