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 |
||
|---|---|---|
| .. | ||
| cow.rs | ||
| drain.rs | ||
| drain_filter.rs | ||
| in_place_drop.rs | ||
| into_iter.rs | ||
| is_zero.rs | ||
| mod.rs | ||
| partial_eq.rs | ||
| set_len_on_drop.rs | ||
| source_iter_marker.rs | ||
| spec_extend.rs | ||
| spec_from_elem.rs | ||
| spec_from_iter.rs | ||
| spec_from_iter_nested.rs | ||
| splice.rs | ||