use core::ptr::NonNull;
use allocator_api2::alloc::Allocator;
use super::Arena;
use crate::internal::chunk::Chunk;
use crate::internal::uninit::Uninit;
impl<A: Allocator + Clone> Arena<A> {
#[inline(always)]
#[cfg_attr(test, mutants::skip)] pub(in crate::arena) fn try_reserve_local<T>(&self) -> Option<Uninit<'_, T>> {
let ticket = self.current().try_alloc_uninit::<T>()?;
self.mark_reference_handout();
Some(unsafe { ticket.rebind() })
}
#[inline(always)]
#[cfg_attr(test, mutants::skip)] pub(crate) fn try_reserve_local_slice<T>(&self, len: usize) -> Option<Uninit<'_, [T]>> {
let ticket = self.current().try_alloc_uninit_slice::<T>(len)?;
self.mark_reference_handout();
Some(unsafe { ticket.rebind() })
}
#[inline(always)]
#[cfg_attr(test, mutants::skip)] pub(in crate::arena) fn try_reserve_local_slice_with_size<T>(&self, len: usize, size: usize) -> Option<Uninit<'_, [T]>> {
let ticket = unsafe { self.current().try_alloc_uninit_slice_with_size::<T>(len, size) }?;
self.mark_reference_handout();
Some(unsafe { ticket.rebind() })
}
#[inline(always)]
#[cfg_attr(test, mutants::skip)] pub(crate) fn try_reserve_freezable_slice<T>(&self, len: usize) -> Option<Uninit<'_, [T]>> {
let ticket = self.current().try_alloc_freezable_slice::<T>(len)?;
self.mark_reference_handout();
Some(unsafe { ticket.rebind() })
}
#[inline(always)]
#[cfg_attr(test, mutants::skip)] pub(in crate::arena) fn try_reserve_local_bytes(&self, len: usize) -> Option<Uninit<'_, [u8]>> {
let ticket = self.current().try_alloc_bytes(len)?;
self.mark_reference_handout();
Some(unsafe { ticket.rebind() })
}
#[inline(always)]
#[cfg_attr(test, mutants::skip)] pub(in crate::arena) fn try_reserve_shared<T>(&self) -> Option<(Uninit<'_, T>, NonNull<Chunk<A>>)> {
let mutator = self.current();
let ticket = mutator.try_alloc_uninit::<T>()?;
Some(unsafe { (ticket.rebind(), mutator.chunk_ptr_unchecked()) })
}
#[inline(always)]
#[cfg_attr(test, mutants::skip)] #[allow(
clippy::type_complexity,
reason = "ticket + chunk-ptr tuple is the natural shape; type alias would obscure rather than clarify"
)]
pub(in crate::arena) unsafe fn try_reserve_shared_slice_with_size<T>(
&self,
len: usize,
payload_bytes: usize,
) -> Option<(Uninit<'_, [T]>, NonNull<Chunk<A>>)> {
let mutator = self.current();
let ticket = unsafe { mutator.try_alloc_uninit_slice_prefixed_with_size::<T>(len, payload_bytes) }?;
Some(unsafe { (ticket.rebind(), mutator.chunk_ptr_unchecked()) })
}
#[inline(always)]
#[cfg_attr(test, mutants::skip)] pub(in crate::arena) fn try_reserve_arc_value<S: crate::internal::thin_dst::Strong, T>(
&self,
) -> Option<(Uninit<'_, T>, NonNull<Chunk<A>>)> {
let (ticket, chunk) = self.current().try_alloc_arc_value::<S, T>()?;
Some(unsafe { (ticket.rebind(), chunk) })
}
#[inline(always)]
#[cfg_attr(test, mutants::skip)] #[allow(
clippy::type_complexity,
reason = "ticket + chunk-ptr tuple is the natural shape; type alias would obscure rather than clarify"
)]
pub(in crate::arena) fn try_reserve_arc_slice<S: crate::internal::thin_dst::Strong, T>(
&self,
len: usize,
) -> Option<(Uninit<'_, [T]>, NonNull<Chunk<A>>)> {
let (ticket, chunk) = self.current().try_alloc_arc_slice::<S, T>(len)?;
Some(unsafe { (ticket.rebind(), chunk) })
}
#[inline(always)]
#[cfg_attr(test, mutants::skip)] #[allow(
clippy::type_complexity,
reason = "ticket + chunk-ptr tuple is the natural shape; type alias would obscure rather than clarify"
)]
pub(in crate::arena) unsafe fn try_reserve_arc_slice_with_size<S: crate::internal::thin_dst::Strong, T>(
&self,
len: usize,
payload_bytes: usize,
) -> Option<(Uninit<'_, [T]>, NonNull<Chunk<A>>)> {
let (ticket, chunk) = unsafe { self.current().try_alloc_arc_slice_with_size::<S, T>(len, payload_bytes) }?;
Some(unsafe { (ticket.rebind(), chunk) })
}
}