| 1 | // FIXME: Replace with `core::hint::{likely, unlikely}` once they are stable. |
| 2 | #[cfg (feature = "nightly" )] |
| 3 | pub(crate) use core::intrinsics::{likely, unlikely}; |
| 4 | |
| 5 | #[cfg (not(feature = "nightly" ))] |
| 6 | #[inline (always)] |
| 7 | #[cold ] |
| 8 | fn cold_path() {} |
| 9 | |
| 10 | #[cfg (not(feature = "nightly" ))] |
| 11 | #[inline (always)] |
| 12 | pub(crate) fn likely(b: bool) -> bool { |
| 13 | if b { |
| 14 | true |
| 15 | } else { |
| 16 | cold_path(); |
| 17 | false |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | #[cfg (not(feature = "nightly" ))] |
| 22 | #[inline (always)] |
| 23 | pub(crate) fn unlikely(b: bool) -> bool { |
| 24 | if b { |
| 25 | cold_path(); |
| 26 | true |
| 27 | } else { |
| 28 | false |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | // FIXME: use strict provenance functions once they are stable. |
| 33 | // Implement it with a transmute for now. |
| 34 | #[inline (always)] |
| 35 | #[allow (clippy::useless_transmute)] // clippy is wrong, cast and transmute are different here |
| 36 | pub(crate) fn invalid_mut<T>(addr: usize) -> *mut T { |
| 37 | unsafe { core::mem::transmute(src:addr) } |
| 38 | } |
| 39 | |