Commit d0032a5e authored by David Michael Barr's avatar David Michael Barr Committed by Luca Barbato

Derive Layout on demand in PlaneData

parent 4a19b42e
......@@ -42,7 +42,6 @@ pub struct PlaneOffset {
pub struct PlaneData<T: Pixel> {
ptr: std::ptr::NonNull<T>,
_marker: PhantomData<T>,
layout: Layout,
len: usize,
}
......@@ -84,7 +83,7 @@ impl<T: Pixel> std::ops::DerefMut for PlaneData<T> {
impl<T: Pixel> std::ops::Drop for PlaneData<T> {
fn drop(&mut self) {
unsafe {
dealloc(self.ptr.as_ptr() as *mut u8, self.layout);
dealloc(self.ptr.as_ptr() as *mut u8, Self::layout(self.len));
}
}
}
......@@ -96,20 +95,21 @@ impl<T: Pixel> PlaneData<T> {
#[cfg(not(windows))]
const DATA_ALIGNMENT_LOG2: usize = 5;
unsafe fn new_uninitialized(len: usize) -> Self {
let layout = Layout::from_size_align_unchecked(
unsafe fn layout(len: usize) -> Layout {
Layout::from_size_align_unchecked(
len * mem::size_of::<T>(),
1 << Self::DATA_ALIGNMENT_LOG2
);
)
}
unsafe fn new_uninitialized(len: usize) -> Self {
let ptr = {
let ptr = alloc(layout) as *mut T;
let ptr = alloc(Self::layout(len)) as *mut T;
std::ptr::NonNull::new_unchecked(ptr)
};
PlaneData {
ptr,
layout,
len,
_marker: PhantomData
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment