NewBuffer: use vec! instead of resizing vec

This commit is contained in:
Alex Janka 2024-11-19 09:56:18 +11:00
parent 31d269852c
commit 0cb78d5a8f

View file

@ -41,10 +41,8 @@ where
type BufferType = T;
fn new_buffer(default: Self::BufferType) -> Self {
let mut v: Vec<T> = Vec::new();
v.resize(SIZE, default);
let temp = v.into_boxed_slice();
unsafe { Box::from_raw(Box::into_raw(temp) as *mut [T; SIZE]) }
let temp = vec![default; SIZE].into_boxed_slice();
unsafe { Box::from_raw(Box::into_raw(temp).cast::<[T; SIZE]>()) }
}
}