Skip to content

Commit 55ea34d

Browse files
committed
Better branch likelyness on stable
It uses uses the `#[cold]` attribute to get a similar effect
1 parent d00d483 commit 55ea34d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/raw/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,23 @@ use self::imp::Group;
4343
// consistently improves performance by 10-15%.
4444
#[cfg(feature = "nightly")]
4545
use core::intrinsics::{likely, unlikely};
46+
47+
#[cfg(not(feature = "nightly"))]
48+
#[inline]
49+
#[cold]
50+
fn cold() {}
51+
4652
#[cfg(not(feature = "nightly"))]
4753
#[inline]
4854
fn likely(b: bool) -> bool {
55+
if !b { cold() }
4956
b
5057
}
5158
#[cfg(not(feature = "nightly"))]
59+
#[cold]
5260
#[inline]
5361
fn unlikely(b: bool) -> bool {
62+
if b { cold() }
5463
b
5564
}
5665

0 commit comments

Comments
 (0)