mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-26 22:53:28 +00:00
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:
parent
8f8092cc32
commit
58b1a127d6
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user