Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 956a84b

Browse files
committed
Optimize SbTag::eq
The code before generated really bad code with a branch. This nudges LLVM towards being smarter and simply comparing the integers.
1 parent b8d5ee0 commit 956a84b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/stacked_borrows.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,27 @@ pub type CallId = NonZeroU64;
2727
pub type AllocExtra = Stacks;
2828

2929
/// Tracking pointer provenance
30-
#[derive(Copy, Clone, Hash, PartialEq, Eq)]
30+
#[derive(Copy, Clone, Hash, Eq)]
3131
pub enum SbTag {
3232
Tagged(PtrId),
3333
Untagged,
3434
}
3535

36+
impl SbTag {
37+
fn as_u64(self) -> u64 {
38+
match self {
39+
SbTag::Tagged(id) => id.get(),
40+
SbTag::Untagged => 0,
41+
}
42+
}
43+
}
44+
45+
impl PartialEq for SbTag {
46+
fn eq(&self, other: &Self) -> bool {
47+
self.as_u64() == other.as_u64()
48+
}
49+
}
50+
3651
impl fmt::Debug for SbTag {
3752
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3853
match self {

0 commit comments

Comments
 (0)