| 1 |
//! Hints to the compiler that affects how code should be emitted or optimized. |
| 2 |
|
| 3 |
/// Indicate that a given branch is **not** likely to be taken, relatively speaking. |
| 4 |
#[inline(always)] |
| 5 |
#[cold] |
| 6 |
pub(crate) const fn cold_path() {} |
| 7 |
|
| 8 |
/// Indicate that a given condition is likely to be true. |
| 9 |
#[inline(always)] |
| 10 |
pub(crate) const fn likely(b: bool) -> bool { |
| 11 |
if !b { |
| 12 |
cold_path(); |
| 13 |
} |
| 14 |
b |
| 15 |
} |
| 16 |
|
| 17 |
/// Indicate that a given condition is likely to be false. |
| 18 |
#[inline(always)] |
| 19 |
pub(crate) const fn unlikely(b: bool) -> bool { |
| 20 |
if b { |
| 21 |
cold_path(); |
| 22 |
} |
| 23 |
b |
| 24 |
} |