Handle use of unlikely on older rustc
use core::alloc::{AllocErr, Layout};
use core::cmp;
use core::convert::TryFrom;
-use core::intrinsics::unlikely;
use core::mem;
use core::ptr::{self, NonNull};
@@ -16,6 +15,13 @@ use crate::sorted::{SortKey, SortOrder, Sortable};
use super::{Block, BlockFooter, BlockRef, FreeBlockRef, FreeBlocks};
+macro_rules! unlikely {
+ ($e:expr) => {{
+ #[allow(unused_unsafe)]
+ unsafe { core::intrinsics::unlikely($e) }
+ }}
+}
+
/// This struct extends `Block` with extra metadata when free.
///
/// When a block is allocated, it is unlinked from the trees it
@@ -163,7 +169,7 @@ impl FreeBlock {
/// that, it is _only_ designed to be accessed by one thread at a time.
pub fn try_alloc(&mut self, layout: &Layout) -> Result<NonNull<u8>, AllocErr> {
// This is here as a safety against trying to use a FreeBlock twice
- if unlikely(!self.header.is_free()) {
+ if unlikely!(!self.header.is_free()) {
debug_assert!(
!self.header.is_free(),
"tried to allocate a free block twice"
