authorgravatar for leroycepearson@geemili.xyzLeRoyce Pearson <leroycepearson@geemili.xyz> 2020-03-06 21:58:15-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-25 13:48:43-04:00
log50cbf1f3aa636badec64bcd6d1905cd3c8d67c16
treee76bd3cca9ea7c1cf70696bd754c6d7d11f084b9
parentfde188aadcc8c7ff279c9365e38b1bec114af08b

Add slice and array support to `add` method


1 files changed, 17 insertions(+), 2 deletions(-)

lib/std/cache_hash.zig+17-2
...@@ -98,6 +98,21 @@ pub const CacheHash = struct {...@@ -98,6 +98,21 @@ pub const CacheHash = struct {
98 switch (@typeInfo(val_type)) {98 switch (@typeInfo(val_type)) {
99 .Int => self.addInt(val),99 .Int => self.addInt(val),
100 .Bool => self.addBool(val),100 .Bool => self.addBool(val),
101 .Array => |array_info| if (array_info.child == u8) {
102 self.addSlice(val[0..]);
103 } else {
104 @compileError("Unsupported array type");
105 },
106 .Pointer => |ptr_info| switch (ptr_info.size) {
107 .Slice => if (ptr_info.child == u8) {
108 self.addSlice(val);
109 },
110 .One => self.add(val.*),
111 else => {
112 @compileLog("Pointer type: ", ptr_info.size, ptr_info.child);
113 @compileError("Unsupported pointer type");
114 },
115 },
101 else => @compileError("Unsupported type"),116 else => @compileError("Unsupported type"),
102 }117 }
103 }118 }
...@@ -328,7 +343,7 @@ test "cache file and the recall it" {...@@ -328,7 +343,7 @@ test "cache file and the recall it" {
328343
329 ch.add(true);344 ch.add(true);
330 ch.add(@as(u16, 1234));345 ch.add(@as(u16, 1234));
331 ch.addSlice("1234");346 ch.add("1234");
332 try ch.cache_file("test.txt");347 try ch.cache_file("test.txt");
333348
334 // There should be nothing in the cache349 // There should be nothing in the cache
...@@ -342,7 +357,7 @@ test "cache file and the recall it" {...@@ -342,7 +357,7 @@ test "cache file and the recall it" {
342357
343 ch.add(true);358 ch.add(true);
344 ch.add(@as(u16, 1234));359 ch.add(@as(u16, 1234));
345 ch.addSlice("1234");360 ch.add("1234");
346 try ch.cache_file("test.txt");361 try ch.cache_file("test.txt");
347362
348 // Cache hit! We just "built" the same file363 // Cache hit! We just "built" the same file