| ... | @@ -59,14 +59,14 @@ pub const CacheHash = struct { | ... | @@ -59,14 +59,14 @@ pub const CacheHash = struct { |
| 59 | }; | 59 | }; |
| 60 | } | 60 | } |
| 61 | | 61 | |
| 62 | pub fn cache_buf(self: *@This(), val: []const u8) void { | 62 | pub fn addSlice(self: *@This(), val: []const u8) void { |
| 63 | debug.assert(self.manifest_file == null); | 63 | debug.assert(self.manifest_file == null); |
| 64 | | 64 | |
| 65 | self.blake3.update(val); | 65 | self.blake3.update(val); |
| 66 | self.blake3.update(&[_]u8{0}); | 66 | self.blake3.update(&[_]u8{0}); |
| 67 | } | 67 | } |
| 68 | | 68 | |
| 69 | pub fn cache(self: *@This(), val: var) void { | 69 | pub fn add(self: *@This(), val: var) void { |
| 70 | debug.assert(self.manifest_file == null); | 70 | debug.assert(self.manifest_file == null); |
| 71 | | 71 | |
| 72 | const val_type = @TypeOf(val); | 72 | const val_type = @TypeOf(val); |
| ... | @@ -75,7 +75,7 @@ pub const CacheHash = struct { | ... | @@ -75,7 +75,7 @@ pub const CacheHash = struct { |
| 75 | const buf_len = @divExact(int_info.bits, 8); | 75 | const buf_len = @divExact(int_info.bits, 8); |
| 76 | var buf: [buf_len]u8 = undefined; | 76 | var buf: [buf_len]u8 = undefined; |
| 77 | mem.writeIntNative(val_type, &buf, val); | 77 | mem.writeIntNative(val_type, &buf, val); |
| 78 | self.cache_buf(&buf); | 78 | self.addSlice(&buf); |
| 79 | } else { | 79 | } else { |
| 80 | @compileError("Unsupported integer size. Please use a multiple of 8, manually convert to a u8 slice."); | 80 | @compileError("Unsupported integer size. Please use a multiple of 8, manually convert to a u8 slice."); |
| 81 | }, | 81 | }, |
| ... | @@ -94,7 +94,7 @@ pub const CacheHash = struct { | ... | @@ -94,7 +94,7 @@ pub const CacheHash = struct { |
| 94 | var cache_hash_file = try self.files.addOne(); | 94 | var cache_hash_file = try self.files.addOne(); |
| 95 | cache_hash_file.path = try fs.path.resolve(self.alloc, &[_][]const u8{file_path}); | 95 | cache_hash_file.path = try fs.path.resolve(self.alloc, &[_][]const u8{file_path}); |
| 96 | | 96 | |
| 97 | self.cache_buf(cache_hash_file.path.?); | 97 | self.addSlice(cache_hash_file.path.?); |
| 98 | } | 98 | } |
| 99 | | 99 | |
| 100 | pub fn hit(self: *@This(), out_digest: *ArrayList(u8)) !bool { | 100 | pub fn hit(self: *@This(), out_digest: *ArrayList(u8)) !bool { |
| ... | @@ -312,9 +312,9 @@ test "cache file and the recall it" { | ... | @@ -312,9 +312,9 @@ test "cache file and the recall it" { |
| 312 | var ch = try CacheHash.init(testing.allocator, temp_manifest_dir); | 312 | var ch = try CacheHash.init(testing.allocator, temp_manifest_dir); |
| 313 | defer ch.release(); | 313 | defer ch.release(); |
| 314 | | 314 | |
| 315 | ch.cache(true); | 315 | ch.add(true); |
| 316 | ch.cache(@as(u16, 1234)); | 316 | ch.add(@as(u16, 1234)); |
| 317 | ch.cache_buf("1234"); | 317 | ch.addSlice("1234"); |
| 318 | try ch.cache_file("test.txt"); | 318 | try ch.cache_file("test.txt"); |
| 319 | | 319 | |
| 320 | // There should be nothing in the cache | 320 | // There should be nothing in the cache |
| ... | @@ -326,9 +326,9 @@ test "cache file and the recall it" { | ... | @@ -326,9 +326,9 @@ test "cache file and the recall it" { |
| 326 | var ch = try CacheHash.init(testing.allocator, temp_manifest_dir); | 326 | var ch = try CacheHash.init(testing.allocator, temp_manifest_dir); |
| 327 | defer ch.release(); | 327 | defer ch.release(); |
| 328 | | 328 | |
| 329 | ch.cache(true); | 329 | ch.add(true); |
| 330 | ch.cache(@as(u16, 1234)); | 330 | ch.add(@as(u16, 1234)); |
| 331 | ch.cache_buf("1234"); | 331 | ch.addSlice("1234"); |
| 332 | try ch.cache_file("test.txt"); | 332 | try ch.cache_file("test.txt"); |
| 333 | | 333 | |
| 334 | // Cache hit! We just "built" the same file | 334 | // Cache hit! We just "built" the same file |