From f3b0f1fba0e7adacaf3237999221d51f414985fc Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sat, 25 Jan 2025 02:14:13 -0800 Subject: [PATCH] Don't check if the same files exist 248 extra times (#16747) --- build.zig | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/build.zig b/build.zig index abcefc752b..01ebdaaeea 100644 --- a/build.zig +++ b/build.zig @@ -152,6 +152,7 @@ pub fn getCpuModel(os: OperatingSystem, arch: Arch) ?Target.Query.CpuModel { pub fn build(b: *Build) !void { std.log.info("zig compiler v{s}", .{builtin.zig_version_string}); + checked_file_exists = std.AutoHashMap(u64, void).init(b.allocator); b.zig_lib_dir = b.zig_lib_dir orelse b.path("vendor/zig/lib"); @@ -481,9 +482,15 @@ pub fn addInstallObjectFile( }, b.fmt("{s}.o", .{name})).step; } +var checked_file_exists: std.AutoHashMap(u64, void) = undefined; fn exists(path: []const u8) bool { - const file = std.fs.openFileAbsolute(path, .{ .mode = .read_only }) catch return false; - file.close(); + const entry = checked_file_exists.getOrPut(std.hash.Wyhash.hash(0, path)) catch unreachable; + if (entry.found_existing) { + // It would've panicked. + return true; + } + + std.fs.accessAbsolute(path, .{ .mode = .read_only }) catch return false; return true; }