Skip to content

Commit a301ff0

Browse files
committed
Auto merge of #209 - a1phyr:stable_likely, r=Amanieu
Better branch likelyness on stable It uses uses the `#[cold]` attribute to get a similar effect as `core::intrinsics::{likely, unlikely}` on stable (10-15% on some benchmarks)
2 parents d00d483 + bbda6e0 commit a301ff0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/raw/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,24 @@ use self::imp::Group;
4343
// consistently improves performance by 10-15%.
4444
#[cfg(feature = "nightly")]
4545
use core::intrinsics::{likely, unlikely};
46+
47+
// On stable we can use #[cold] to get a equivalent effect: this attributes
48+
// suggests that the function is unlikely to be called
49+
#[cfg(not(feature = "nightly"))]
50+
#[inline]
51+
#[cold]
52+
fn cold() {}
53+
4654
#[cfg(not(feature = "nightly"))]
4755
#[inline]
4856
fn likely(b: bool) -> bool {
57+
if !b { cold() }
4958
b
5059
}
5160
#[cfg(not(feature = "nightly"))]
5261
#[inline]
5362
fn unlikely(b: bool) -> bool {
63+
if b { cold() }
5464
b
5565
}
5666

0 commit comments

Comments
 (0)