| ... | @@ -56,9 +56,6 @@ pub fn hashPointer(hasher: anytype, key: anytype, comptime strat: HashStrategy) | ... | @@ -56,9 +56,6 @@ pub fn hashPointer(hasher: anytype, key: anytype, comptime strat: HashStrategy) |
| 56 | pub fn hashArray(hasher: anytype, key: anytype, comptime strat: HashStrategy) void { | 56 | pub fn hashArray(hasher: anytype, key: anytype, comptime strat: HashStrategy) void { |
| 57 | switch (strat) { | 57 | switch (strat) { |
| 58 | .Shallow => { | 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 | for (key) |element| { | 59 | for (key) |element| { |
| 63 | hash(hasher, element, .Shallow); | 60 | hash(hasher, element, .Shallow); |
| 64 | } | 61 | } |
| ... | @@ -75,6 +72,12 @@ pub fn hashArray(hasher: anytype, key: anytype, comptime strat: HashStrategy) vo | ... | @@ -75,6 +72,12 @@ pub fn hashArray(hasher: anytype, key: anytype, comptime strat: HashStrategy) vo |
| 75 | /// Strategy is provided to determine if pointers should be followed or not. | 72 | /// Strategy is provided to determine if pointers should be followed or not. |
| 76 | pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void { | 73 | pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void { |
| 77 | const Key = @TypeOf(key); | 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 | switch (@typeInfo(Key)) { | 81 | switch (@typeInfo(Key)) { |
| 79 | .NoReturn, | 82 | .NoReturn, |
| 80 | .Opaque, | 83 | .Opaque, |
| ... | @@ -119,9 +122,6 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void { | ... | @@ -119,9 +122,6 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void { |
| 119 | }, | 122 | }, |
| 120 | | 123 | |
| 121 | .Struct => |info| { | 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 | inline for (info.fields) |field| { | 125 | inline for (info.fields) |field| { |
| 126 | // We reuse the hash of the previous field as the seed for the | 126 | // We reuse the hash of the previous field as the seed for the |
| 127 | // next one so that they're dependant. | 127 | // next one so that they're dependant. |