Avoid allocations and copying in Vec::leak

Don't shrink the Vec (by calling into_boxed_slice) before leaking it.
This commit is contained in:
Matt Brubeck 2021-09-28 13:03:31 -07:00
parent 8f8092cc32
commit 58b1a127d6

View File

@ -1976,7 +1976,8 @@ impl<T, A: Allocator> Vec<T, A> {
where
A: 'a,
{
Box::leak(self.into_boxed_slice())
let mut me = ManuallyDrop::new(self);
unsafe { slice::from_raw_parts_mut(me.as_mut_ptr(), me.len) }
}
/// Returns the remaining spare capacity of the vector as a slice of