aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Build/Cache/Path.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-07-08 23:41:08 -0700
committerAndrew Kelley <andrew@ziglang.org>2024-07-12 00:14:07 -0700
commitdeea36250ffe458d92b32b1ad090b8a958ba8082 (patch)
tree26474e427b254aa7aaaaccebfb6470a4f7d83768 /lib/std/Build/Cache/Path.zig
parent6c64090e7af56ccbf374e1a927fe232b340ed681 (diff)
downloadzig-deea36250ffe458d92b32b1ad090b8a958ba8082.tar.gz
zig-deea36250ffe458d92b32b1ad090b8a958ba8082.zip
std.Build.Cache.Path: add `subPathOpt` and `TableAdapter`
Helpful methods when using one of these structs as a hash table key.
Diffstat (limited to 'lib/std/Build/Cache/Path.zig')
-rw-r--r--lib/std/Build/Cache/Path.zig20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/std/Build/Cache/Path.zig b/lib/std/Build/Cache/Path.zig
index cb6e4c7087..89dba6b577 100644
--- a/lib/std/Build/Cache/Path.zig
+++ b/lib/std/Build/Cache/Path.zig
@@ -151,6 +151,26 @@ pub fn eql(self: Path, other: Path) bool {
return self.root_dir.eql(other.root_dir) and std.mem.eql(u8, self.sub_path, other.sub_path);
}
+pub fn subPathOpt(self: Path) ?[]const u8 {
+ return if (self.sub_path.len == 0) null else self.sub_path;
+}
+
+/// Useful to make `Path` a key in `std.ArrayHashMap`.
+pub const TableAdapter = struct {
+ pub const Hash = std.hash.Wyhash;
+
+ pub fn hash(self: TableAdapter, a: Cache.Path) u32 {
+ _ = self;
+ const seed: u32 = @bitCast(a.root_dir.handle.fd);
+ return @truncate(Hash.hash(seed, a.sub_path));
+ }
+ pub fn eql(self: TableAdapter, a: Cache.Path, b: Cache.Path, b_index: usize) bool {
+ _ = self;
+ _ = b_index;
+ return a.eql(b);
+ }
+};
+
const Path = @This();
const std = @import("../../std.zig");
const fs = std.fs;