about summary refs log tree commit diff
path: root/compiler/rustc_codegen_gcc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-10-15 15:55:08 +0000
committerbors <bors@rust-lang.org>2021-10-15 15:55:08 +0000
commit265fef45f20e3b8ed9495201b5d02bab1210f0f9 (patch)
treefe4e428ff5bc108a76e956e6a17d526bec8f613c /compiler/rustc_codegen_gcc
parentaf9b508e1d6c83a8f0e6f5c0b2b75598aa37ed27 (diff)
parentdf15b289f39c497d16fac694c6982fbdfa2e6fe2 (diff)
downloadrust-265fef45f20e3b8ed9495201b5d02bab1210f0f9.tar.gz
rust-265fef45f20e3b8ed9495201b5d02bab1210f0f9.zip
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
Diffstat (limited to 'compiler/rustc_codegen_gcc')
0 files changed, 0 insertions, 0 deletions