| ... | @@ -66,24 +66,38 @@ pub const CacheHash = struct { | ... | @@ -66,24 +66,38 @@ pub const CacheHash = struct { |
| 66 | self.blake3.update(&[_]u8{0}); | 66 | self.blake3.update(&[_]u8{0}); |
| 67 | } | 67 | } |
| 68 | | 68 | |
| 69 | pub fn add(self: *@This(), val: var) void { | 69 | pub fn addBool(self: *@This(), val: bool) void { |
| 70 | debug.assert(self.manifest_file == null); | 70 | debug.assert(self.manifest_file == null); |
| | 71 | self.blake3.update(&[_]u8{@boolToInt(val)}); |
| | 72 | } |
| | 73 | |
| | 74 | pub fn addInt(self: *@This(), val: var) void { |
| | 75 | debug.assert(self.manifest_file == null); |
| | 76 | |
| | 77 | switch (@typeInfo(@TypeOf(val))) { |
| | 78 | .Int => |int_info| { |
| | 79 | if (int_info.bits == 0 or int_info.bits % 8 != 0) { |
| | 80 | @compileError("Unsupported integer size. Please use a multiple of 8, manually convert to a u8 slice."); |
| | 81 | } |
| 71 | | 82 | |
| 72 | const val_type = @TypeOf(val); | | |
| 73 | switch (@typeInfo(val_type)) { | | |
| 74 | .Int => |int_info| if (int_info.bits != 0 and int_info.bits % 8 == 0) { | | |
| 75 | const buf_len = @divExact(int_info.bits, 8); | 83 | const buf_len = @divExact(int_info.bits, 8); |
| 76 | var buf: [buf_len]u8 = undefined; | 84 | var buf: [buf_len]u8 = undefined; |
| 77 | mem.writeIntNative(val_type, &buf, val); | 85 | mem.writeIntNative(@TypeOf(val), &buf, val); |
| 78 | self.addSlice(&buf); | 86 | self.addSlice(&buf); |
| 79 | } else { | 87 | |
| 80 | @compileError("Unsupported integer size. Please use a multiple of 8, manually convert to a u8 slice."); | 88 | self.blake3.update(&[_]u8{0}); |
| 81 | }, | | |
| 82 | .Bool => { | | |
| 83 | var buf: [1]u8 = undefined; | | |
| 84 | buf[0] = if (val) 1 else 0; | | |
| 85 | self.blake3.update(&buf); | | |
| 86 | }, | 89 | }, |
| | 90 | else => @compileError("Type must be an integer."), |
| | 91 | } |
| | 92 | } |
| | 93 | |
| | 94 | pub fn add(self: *@This(), val: var) void { |
| | 95 | debug.assert(self.manifest_file == null); |
| | 96 | |
| | 97 | const val_type = @TypeOf(val); |
| | 98 | switch (@typeInfo(val_type)) { |
| | 99 | .Int => self.addInt(val), |
| | 100 | .Bool => self.addBool(val), |
| 87 | else => @compileError("Unsupported type"), | 101 | else => @compileError("Unsupported type"), |
| 88 | } | 102 | } |
| 89 | } | 103 | } |