1#[cold]
5#[inline]
6const fn cold_fn() {}
7
8#[inline]
10pub const fn likely(b: bool) -> bool {
11 if !b {
12 cold_fn();
13 }
14 b
15}
16
17#[inline]
19pub const fn unlikely(b: bool) -> bool {
20 if b {
21 cold_fn();
22 }
23 b
24}
25
26#[cfg(test)]
27mod hints {
28 use super::*;
29
30 #[test]
31 fn sanity_checks_for_likely() {
32 assert!(likely(true));
33 assert!(!likely(false));
34 }
35
36 #[test]
37 fn sanity_checks_for_unlikely() {
38 assert!(unlikely(true));
39 assert!(!unlikely(false));
40 }
41}