1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//! `likely()` and `unlikely()` hints.
//! `core::intrinsics::{likely, unlikely}` are unstable fo now.
//! On stable we can use `#[cold]` to get the same effect.

#[inline]
#[cold]
fn cold() {}

#[inline(always)]
pub fn likely(b: bool) -> bool {
    if !b {
        cold();
    }
    b
}

#[inline(always)]
pub fn unlikely(b: bool) -> bool {
    if b {
        cold();
    }
    b
}