| ... | ... | @@ -91,15 +91,21 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void { |
| 91 | 91 | |
| 92 | 92 | // Help the optimizer see that hashing an int is easy by inlining! |
| 93 | 93 | // TODO Check if the situation is better after #561 is resolved. |
| 94 | | .Int => { |
| 95 | | if (comptime meta.trait.hasUniqueRepresentation(Key)) { |
| 96 | | @call(.always_inline, Hasher.update, .{ hasher, std.mem.asBytes(&key) }); |
| 97 | | } else { |
| 98 | | // Take only the part containing the key value, the remaining |
| 99 | | // bytes are undefined and must not be hashed! |
| 100 | | const byte_size = comptime std.math.divCeil(comptime_int, @bitSizeOf(Key), 8) catch unreachable; |
| 101 | | @call(.always_inline, Hasher.update, .{ hasher, std.mem.asBytes(&key)[0..byte_size] }); |
| 102 | | } |
| 94 | .Int => |int| switch (int.signedness) { |
| 95 | .signed => hash(hasher, @bitCast(@Type(.{ .Int = .{ |
| 96 | .bits = int.bits, |
| 97 | .signedness = .unsigned, |
| 98 | } }), key), strat), |
| 99 | .unsigned => { |
| 100 | if (comptime meta.trait.hasUniqueRepresentation(Key)) { |
| 101 | @call(.always_inline, Hasher.update, .{ hasher, std.mem.asBytes(&key) }); |
| 102 | } else { |
| 103 | // Take only the part containing the key value, the remaining |
| 104 | // bytes are undefined and must not be hashed! |
| 105 | const byte_size = comptime std.math.divCeil(comptime_int, @bitSizeOf(Key), 8) catch unreachable; |
| 106 | @call(.always_inline, Hasher.update, .{ hasher, std.mem.asBytes(&key)[0..byte_size] }); |
| 107 | } |
| 108 | }, |
| 103 | 109 | }, |
| 104 | 110 | |
| 105 | 111 | .Bool => hash(hasher, @boolToInt(key), strat), |