@@ -122,12 +122,9 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void {
|
||||
.Array => hashArray(hasher, key, strat),
|
||||
|
||||
.Vector => |info| {
|
||||
if (std.meta.bitCount(info.child) % 8 == 0) {
|
||||
// If there's no unused bits in the child type, we can just hash
|
||||
// this as an array of bytes.
|
||||
if (comptime meta.trait.hasUniqueRepresentation(Key)) {
|
||||
hasher.update(mem.asBytes(&key));
|
||||
} else {
|
||||
// Otherwise, hash every element.
|
||||
comptime var i = 0;
|
||||
inline while (i < info.len) : (i += 1) {
|
||||
hash(hasher, key[i], strat);
|
||||
|
||||
@@ -582,7 +582,7 @@ pub fn hasUniqueRepresentation(comptime T: type) bool {
|
||||
return @sizeOf(T) == sum_size;
|
||||
},
|
||||
|
||||
.Vector => |info| return comptime hasUniqueRepresentation(info.child),
|
||||
.Vector => |info| return comptime hasUniqueRepresentation(info.child) and @sizeOf(T) == @sizeOf(info.child) * info.len,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -653,4 +653,7 @@ test "std.meta.trait.hasUniqueRepresentation" {
|
||||
|
||||
try testing.expect(!hasUniqueRepresentation([]u8));
|
||||
try testing.expect(!hasUniqueRepresentation([]const u8));
|
||||
|
||||
try testing.expect(hasUniqueRepresentation(@Vector(4, u16)));
|
||||
try testing.expect(!hasUniqueRepresentation(@Vector(3, u16)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user