diff options
| author | Matt Brubeck <mbrubeck@limpet.net> | 2021-09-28 13:03:31 -0700 |
|---|---|---|
| committer | Matt Brubeck <mbrubeck@limpet.net> | 2021-09-28 13:23:54 -0700 |
| commit | 58b1a127d66b71e1a2180b509856f2c52feca9b3 (patch) | |
| tree | c2b9192703156e8259e7fb2b0afde55afdbbd014 /library/alloc/src/vec | |
| parent | 8f8092cc32ec171becef8ceacec7dbb06c5d7d7e (diff) | |
| download | rust-58b1a127d66b71e1a2180b509856f2c52feca9b3.tar.gz rust-58b1a127d66b71e1a2180b509856f2c52feca9b3.zip | |
Avoid allocations and copying in Vec::leak
Don't shrink the Vec (by calling into_boxed_slice) before leaking it.
Diffstat (limited to 'library/alloc/src/vec')
| -rw-r--r-- | library/alloc/src/vec/mod.rs | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index c37ec375561..a8b939bc249 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -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 |
