| ... | ... | @@ -56,9 +56,6 @@ pub fn hashPointer(hasher: anytype, key: anytype, comptime strat: HashStrategy) |
| 56 | 56 | pub fn hashArray(hasher: anytype, key: anytype, comptime strat: HashStrategy) void { |
| 57 | 57 | switch (strat) { |
| 58 | 58 | .Shallow => { |
| 59 | | // TODO detect via a trait when Key has no padding bits to |
| 60 | | // hash it as an array of bytes. |
| 61 | | // Otherwise, hash every element. |
| 62 | 59 | for (key) |element| { |
| 63 | 60 | hash(hasher, element, .Shallow); |
| 64 | 61 | } |
| ... | ... | @@ -75,6 +72,12 @@ pub fn hashArray(hasher: anytype, key: anytype, comptime strat: HashStrategy) vo |
| 75 | 72 | /// Strategy is provided to determine if pointers should be followed or not. |
| 76 | 73 | pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void { |
| 77 | 74 | const Key = @TypeOf(key); |
| 75 | |
| 76 | if (strat == .Shallow and comptime meta.trait.hasUniqueRepresentation(Key)) { |
| 77 | @call(.{ .modifier = .always_inline }, hasher.update, .{mem.asBytes(&key)}); |
| 78 | return; |
| 79 | } |
| 80 | |
| 78 | 81 | switch (@typeInfo(Key)) { |
| 79 | 82 | .NoReturn, |
| 80 | 83 | .Opaque, |
| ... | ... | @@ -119,9 +122,6 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void { |
| 119 | 122 | }, |
| 120 | 123 | |
| 121 | 124 | .Struct => |info| { |
| 122 | | // TODO detect via a trait when Key has no padding bits to |
| 123 | | // hash it as an array of bytes. |
| 124 | | // Otherwise, hash every field. |
| 125 | 125 | inline for (info.fields) |field| { |
| 126 | 126 | // We reuse the hash of the previous field as the seed for the |
| 127 | 127 | // next one so that they're dependant. |