rust/library/alloc/src
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
..
alloc Rename AllocRef to Allocator and (de)alloc to (de)allocate 2020-12-04 14:47:15 +01:00
collections Auto merge of #88717 - tabokie:vecdeque-fast-append, r=m-ou-se 2021-10-15 12:51:31 +00:00
prelude mv std libs to library/ 2020-07-27 19:51:13 -05:00
raw_vec Rename AllocRef to Allocator and (de)alloc to (de)allocate 2020-12-04 14:47:15 +01:00
rc Re-stabilize Weak::as_ptr &friends for unsized T 2021-01-06 19:30:22 -05:00
sync Rollup merge of #80764 - CAD97:weak-unsized-as-ptr-again, r=RalfJung 2021-01-16 17:29:56 +00:00
vec Auto merge of #89337 - mbrubeck:vec-leak, r=m-ou-se 2021-10-15 15:55:08 +00:00
alloc.rs Use Rvalue::ShallowInitBox for box expression 2021-09-25 01:08:41 +01:00
borrow.rs Const Deref 2021-09-15 03:06:53 +00:00
boxed.rs Add #[must_use] to alloc constructors 2021-10-10 02:19:30 -04:00
fmt.rs Apply 16 commits (squashed) 2021-09-25 20:04:35 +02:00
lib.rs Fix missing remaining compiler specific cfg information 2021-10-14 11:39:30 +02:00
macros.rs Remove alloc/malloc/calloc/realloc doc aliases 2021-06-30 19:59:39 +01:00
raw_vec.rs Add #[must_use] to alloc constructors 2021-10-10 02:19:30 -04:00
rc.rs Rollup merge of #89796 - jkugelman:must-use-non-mutating-verb-methods, r=joshtriplett 2021-10-12 14:53:10 +02:00
slice.rs Add #[must_use] to string/char transformation methods 2021-10-09 01:01:40 -04:00
str.rs Fix uppercase/lowercase error 2021-10-12 08:53:54 -04:00
string.rs Rollup merge of #89778 - jkugelman:must-use-as_type-conversions, r=joshtriplett 2021-10-12 14:53:08 +02:00
sync.rs Rollup merge of #89796 - jkugelman:must-use-non-mutating-verb-methods, r=joshtriplett 2021-10-12 14:53:10 +02:00
task.rs Document From implementations for Waker and RawWaker 2021-04-22 14:16:33 -07:00
tests.rs Fix alloc::test::test_show 2021-04-21 15:45:41 +02:00