| ... | ... | @@ -99,7 +99,16 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void { |
| 99 | 99 | |
| 100 | 100 | // Help the optimizer see that hashing an int is easy by inlining! |
| 101 | 101 | // TODO Check if the situation is better after #561 is resolved. |
| 102 | | .Int => @call(.{ .modifier = .always_inline }, hasher.update, .{std.mem.asBytes(&key)}), |
| 102 | .Int => { |
| 103 | if (comptime meta.trait.hasUniqueRepresentation(Key)) { |
| 104 | @call(.{ .modifier = .always_inline }, hasher.update, .{std.mem.asBytes(&key)}); |
| 105 | } else { |
| 106 | // Take only the part containing the key value, the remaining |
| 107 | // bytes are undefined and must not be hashed! |
| 108 | const byte_size = comptime std.math.divCeil(comptime_int, @bitSizeOf(Key), 8) catch unreachable; |
| 109 | @call(.{ .modifier = .always_inline }, hasher.update, .{std.mem.asBytes(&key)[0..byte_size]}); |
| 110 | } |
| 111 | }, |
| 103 | 112 | |
| 104 | 113 | .Bool => hash(hasher, @boolToInt(key), strat), |
| 105 | 114 | .Enum => hash(hasher, @enumToInt(key), strat), |