mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 15:54:15 +00:00
Do not inline finish_grow
We also change the specialization of `SpecFromIterNested::from_iter` for `TrustedLen` to use `Vec::with_capacity` when the iterator has a proper size hint, instead of `Vec::new`, avoiding calls to `grow_*` and thus `finish_grow` in some fully inlinable cases, which would regress with this change. Fixes #78471.
This commit is contained in:
parent
87776d7d53
commit
76bd145489
@ -471,6 +471,7 @@ impl<T, A: AllocRef> RawVec<T, A> {
|
||||
// above `RawVec::grow_amortized` for details. (The `A` parameter isn't
|
||||
// significant, because the number of different `A` types seen in practice is
|
||||
// much smaller than the number of `T` types.)
|
||||
#[inline(never)]
|
||||
fn finish_grow<A>(
|
||||
new_layout: Result<Layout, LayoutError>,
|
||||
current_memory: Option<(NonNull<u8>, Layout)>,
|
||||
|
@ -2103,7 +2103,10 @@ where
|
||||
I: TrustedLen<Item = T>,
|
||||
{
|
||||
fn from_iter(iterator: I) -> Self {
|
||||
let mut vector = Vec::new();
|
||||
let mut vector = match iterator.size_hint() {
|
||||
(_, Some(upper)) => Vec::with_capacity(upper),
|
||||
_ => Vec::new(),
|
||||
};
|
||||
// must delegate to spec_extend() since extend() itself delegates
|
||||
// to spec_from for empty Vecs
|
||||
vector.spec_extend(iterator);
|
||||
|
Loading…
Reference in New Issue
Block a user