Skip to content

Commit

Permalink
Do not inline finish_grow
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
glandium committed Dec 8, 2020
1 parent 87776d7 commit 76bd145
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions library/alloc/src/raw_vec.rs
Expand Up @@ -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)>,
Expand Down
5 changes: 4 additions & 1 deletion library/alloc/src/vec.rs
Expand Up @@ -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);
Expand Down

0 comments on commit 76bd145

Please sign in to comment.