rust/library/alloc/src/vec
bors 265fef45f2 Auto merge of #89337 - mbrubeck:vec-leak, r=m-ou-se
Avoid allocations and copying in Vec::leak

The [`Vec::leak`] method (#62195) is currently implemented by calling `Vec::into_boxed_slice` and `Box::leak`.  This shrinks the vector before leaking it, which potentially causes a reallocation and copies the vector's contents.

By avoiding the conversion to `Box`, we can instead leak the vector without any expensive operations, just by returning a slice reference and forgetting the `Vec`.  Users who *want* to shrink the vector first can still do so by calling `shrink_to_fit` explicitly.

**Note:**  This could break code that uses `Box::from_raw` to “un-leak” the slice returned by `Vec::leak`.  However, the `Vec::leak` docs explicitly forbid this, so such code is already incorrect.

[`Vec::leak`]: https://doc.rust-lang.org/stable/std/vec/struct.Vec.html#method.leak
2021-10-15 15:55:08 +00:00
..
cow.rs Document From impls for cow.rs 2021-05-26 14:21:44 +00:00
drain.rs Add #[must_use] to as_type conversions 2021-10-11 13:57:38 -04:00
drain_filter.rs style: applying Rust style 2020-12-29 14:03:30 +00:00
in_place_drop.rs style: applying Rust style 2020-12-29 14:03:30 +00:00
into_iter.rs Rollup merge of #89413 - matthewjasper:spec-marker-fix, r=nikomatsakis 2021-10-04 21:12:35 -07:00
is_zero.rs Fix a typo 2021-05-30 00:06:27 +02:00
mod.rs Auto merge of #89337 - mbrubeck:vec-leak, r=m-ou-se 2021-10-15 15:55:08 +00:00
partial_eq.rs alloc: Add unstable Cfg feature no-global_oom_handling 2021-05-05 16:49:04 -04:00
set_len_on_drop.rs refactor: moved SetLenOnDrop to set_len_on_drop 2020-12-29 14:03:30 +00:00
source_iter_marker.rs Fix standard library for min_specialization changes 2021-09-30 21:42:41 +01:00
spec_extend.rs Add comments around code where ordering is important due for panic-safety 2021-06-22 19:06:55 +02:00
spec_from_elem.rs style: applying Rust style 2020-12-29 14:03:30 +00:00
spec_from_iter.rs Update documentation of SpecFromIter to reflect the removed impls 2021-05-31 21:07:03 +02:00
spec_from_iter_nested.rs panic early when TrustedLen indicates a length > usize::MAX 2021-03-31 23:09:28 +02:00
splice.rs Update expressions where we can use array's IntoIterator implementation 2021-06-02 16:09:04 +06:00