Skip to content

Commit

Permalink
hashmap: remove inline from getIndex now that we have @branchHint
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexicon226 committed Dec 15, 2024
1 parent b58916b commit 690077c
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions lib/std/hash_map.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 because even with unlikely,
// LLVM will want to fallthrough to this case.
@branchHint(.cold);
return null;
}

Expand Down

0 comments on commit 690077c

Please sign in to comment.