pub mod defaults {
pub mod local {
use core::ptr::{copy_nonoverlapping, write_bytes};
use crate::NonZeroLayout;
use crate::local::{LocalAlloc, Allocation};
pub fn alloc_zeroed<'alloc, Alloc>(
this: &'alloc Alloc,
layout: NonZeroLayout
) -> Option<Allocation<'alloc>>
where
Alloc: LocalAlloc<'alloc> + ?Sized,
{
let allocation = this.alloc(layout)?;
unsafe {
write_bytes(allocation.ptr.as_ptr(), 0u8, allocation.layout.size().into());
}
Some(allocation)
}
pub unsafe fn realloc<'alloc, Alloc>(
this: &'alloc Alloc,
alloc: Allocation<'alloc>,
layout: NonZeroLayout
) -> Option<Allocation<'alloc>>
where
Alloc: LocalAlloc<'alloc> + ?Sized,
{
let new_alloc = this.alloc(layout)?;
copy_nonoverlapping(
alloc.ptr.as_ptr(),
new_alloc.ptr.as_ptr(),
core::cmp::min(layout.size(), alloc.layout.size()).get());
this.dealloc(alloc);
Some(new_alloc)
}
}
}