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 {
9898 switch (@typeInfo(val_type)) {
9999 .Int => self.addInt(val),
100100 .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 },
101116 else => @compileError("Unsupported type"),
102117 }
103118 }
......@@ -328,7 +343,7 @@ test "cache file and the recall it" {
328343
329344 ch.add(true);
330345 ch.add(@as(u16, 1234));
331 ch.addSlice("1234");
346 ch.add("1234");
332347 try ch.cache_file("test.txt");
333348
334349 // There should be nothing in the cache
......@@ -342,7 +357,7 @@ test "cache file and the recall it" {
342357
343358 ch.add(true);
344359 ch.add(@as(u16, 1234));
345 ch.addSlice("1234");
360 ch.add("1234");
346361 try ch.cache_file("test.txt");
347362
348363 // Cache hit! We just "built" the same file