aboutsummaryrefslogtreecommitdiff
path: root/lib/std/hash_map.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-12-16 07:27:20 -0500
committerGitHub <noreply@github.com>2024-12-16 07:27:20 -0500
commitd12c0bf90911339c8db0741b257eac251b827b2c (patch)
treea35c9b98cc1e601c09e96983548e2a62c8ad0625 /lib/std/hash_map.zig
parent3a0a9aa9b866ad8483d298c6b891f9b321303bb9 (diff)
parent0fe17ea12a5bc389d8cb0c87027a112a552e9cbc (diff)
downloadzig-d12c0bf90911339c8db0741b257eac251b827b2c.tar.gz
zig-d12c0bf90911339c8db0741b257eac251b827b2c.zip
Merge pull request #22242 from Rexicon226/moar-branch-hint
utilize `@branchHint` more
Diffstat (limited to 'lib/std/hash_map.zig')
-rw-r--r--lib/std/hash_map.zig12
1 files changed, 4 insertions, 8 deletions
diff --git a/lib/std/hash_map.zig b/lib/std/hash_map.zig
index e6f51dc648..2218ff1c5d 100644
--- a/lib/std/hash_map.zig
+++ b/lib/std/hash_map.zig
@@ -1187,17 +1187,13 @@ pub fn HashMapUnmanaged(
}
/// Find the index containing the data for the given key.
- /// Whether this function returns null is almost always
- /// branched on after this function returns, and this function
- /// returns null/not null from separate code paths. We
- /// want the optimizer to remove that branch and instead directly
- /// fuse the basic blocks after the branch to the basic blocks
- /// from this function. To encourage that, this function is
- /// marked as inline.
- inline fn getIndex(self: Self, key: anytype, ctx: anytype) ?usize {
+ fn getIndex(self: Self, key: anytype, ctx: anytype) ?usize {
comptime verifyContext(@TypeOf(ctx), @TypeOf(key), K, Hash, false);
if (self.size == 0) {
+ // We use cold instead of unlikely to force a jump to this case,
+ // no matter the weight of the opposing side.
+ @branchHint(.cold);
return null;
}