| author | |
| committer | |
| log | d4e22e3eb668968fa30f25c382b97629902f0bf8 |
| tree | fa0239b1e16609be866077790b115684ceb39130 |
| parent | d99f55b7cf3b3b15ccbef224f157725b91e40bea |
Closes #9333.2 files changed, 5 insertions(+), 5 deletions(-)
lib/std/hash/auto_hash.zig+1-4| ... | ... | @@ -122,12 +122,9 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void { |
| 122 | 122 | .Array => hashArray(hasher, key, strat), |
| 123 | 123 | |
| 124 | 124 | .Vector => |info| { |
| 125 | if (std.meta.bitCount(info.child) % 8 == 0) { | |
| 126 | // If there's no unused bits in the child type, we can just hash | |
| 127 | // this as an array of bytes. | |
| 125 | if (comptime meta.trait.hasUniqueRepresentation(Key)) { | |
| 128 | 126 | hasher.update(mem.asBytes(&key)); |
| 129 | 127 | } else { |
| 130 | // Otherwise, hash every element. | |
| 131 | 128 | comptime var i = 0; |
| 132 | 129 | inline while (i < info.len) : (i += 1) { |
| 133 | 130 | hash(hasher, key[i], strat); |
lib/std/meta/trait.zig+4-1| ... | ... | @@ -582,7 +582,7 @@ pub fn hasUniqueRepresentation(comptime T: type) bool { |
| 582 | 582 | return @sizeOf(T) == sum_size; |
| 583 | 583 | }, |
| 584 | 584 | |
| 585 | .Vector => |info| return comptime hasUniqueRepresentation(info.child), | |
| 585 | .Vector => |info| return comptime hasUniqueRepresentation(info.child) and @sizeOf(T) == @sizeOf(info.child) * info.len, | |
| 586 | 586 | } |
| 587 | 587 | } |
| 588 | 588 | |
| ... | ... | @@ -653,4 +653,7 @@ test "std.meta.trait.hasUniqueRepresentation" { |
| 653 | 653 | |
| 654 | 654 | try testing.expect(!hasUniqueRepresentation([]u8)); |
| 655 | 655 | try testing.expect(!hasUniqueRepresentation([]const u8)); |
| 656 | ||
| 657 | try testing.expect(hasUniqueRepresentation(@Vector(4, u16))); | |
| 658 | try testing.expect(!hasUniqueRepresentation(@Vector(3, u16))); | |
| 656 | 659 | } |