| ... | @@ -151,6 +151,26 @@ pub fn eql(self: Path, other: Path) bool { | ... | @@ -151,6 +151,26 @@ pub fn eql(self: Path, other: Path) bool { |
| 151 | return self.root_dir.eql(other.root_dir) and std.mem.eql(u8, self.sub_path, other.sub_path); | 151 | return self.root_dir.eql(other.root_dir) and std.mem.eql(u8, self.sub_path, other.sub_path); |
| 152 | } | 152 | } |
| 153 | | 153 | |
| | 154 | pub fn subPathOpt(self: Path) ?[]const u8 { |
| | 155 | return if (self.sub_path.len == 0) null else self.sub_path; |
| | 156 | } |
| | 157 | |
| | 158 | /// Useful to make `Path` a key in `std.ArrayHashMap`. |
| | 159 | pub const TableAdapter = struct { |
| | 160 | pub const Hash = std.hash.Wyhash; |
| | 161 | |
| | 162 | pub fn hash(self: TableAdapter, a: Cache.Path) u32 { |
| | 163 | _ = self; |
| | 164 | const seed: u32 = @bitCast(a.root_dir.handle.fd); |
| | 165 | return @truncate(Hash.hash(seed, a.sub_path)); |
| | 166 | } |
| | 167 | pub fn eql(self: TableAdapter, a: Cache.Path, b: Cache.Path, b_index: usize) bool { |
| | 168 | _ = self; |
| | 169 | _ = b_index; |
| | 170 | return a.eql(b); |
| | 171 | } |
| | 172 | }; |
| | 173 | |
| 154 | const Path = @This(); | 174 | const Path = @This(); |
| 155 | const std = @import("../../std.zig"); | 175 | const std = @import("../../std.zig"); |
| 156 | const fs = std.fs; | 176 | const fs = std.fs; |