commit 54255ee32e1e6c83b04c3e5f2f1dd7e8aa5e0dd7 (tree)
parent 3faf5d38576616d033c343130607189eb9fe613c
Author: Sahnvour <sahnvour@pm.me>
Date: Tue, 16 Jul 2019 22:32:10 +0200
autohash: force inlining of integer hashing so that the optimizer can see the fast path based on key's size which is known at comptime
otherwise it will always outline the call to hasher.update, resulting in much worse performance
Diffstat:
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/std/hash/auto_hash.zig b/std/hash/auto_hash.zig
@@ -21,7 +21,9 @@ pub fn autoHash(hasher: var, key: var) void {
builtin.TypeId.EnumLiteral,
=> @compileError("cannot hash this type"),
- builtin.TypeId.Int => hasher.update(std.mem.asBytes(&key)),
+ // Help the optimizer see that hashing an int is easy by inlining!
+ // TODO Check if the situation is better after #561 is resolved.
+ builtin.TypeId.Int => @inlineCall(hasher.update, std.mem.asBytes(&key)),
builtin.TypeId.Float => |info| autoHash(hasher, @bitCast(@IntType(false, info.bits), key)),