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