Skip to content

Commit 76bd145

Browse files
committed
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.
1 parent 87776d7 commit 76bd145

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

library/alloc/src/raw_vec.rs

+1
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ impl<T, A: AllocRef> RawVec<T, A> {
471471
// above `RawVec::grow_amortized` for details. (The `A` parameter isn't
472472
// significant, because the number of different `A` types seen in practice is
473473
// much smaller than the number of `T` types.)
474+
#[inline(never)]
474475
fn finish_grow<A>(
475476
new_layout: Result<Layout, LayoutError>,
476477
current_memory: Option<(NonNull<u8>, Layout)>,

library/alloc/src/vec.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2103,7 +2103,10 @@ where
21032103
I: TrustedLen<Item = T>,
21042104
{
21052105
fn from_iter(iterator: I) -> Self {
2106-
let mut vector = Vec::new();
2106+
let mut vector = match iterator.size_hint() {
2107+
(_, Some(upper)) => Vec::with_capacity(upper),
2108+
_ => Vec::new(),
2109+
};
21072110
// must delegate to spec_extend() since extend() itself delegates
21082111
// to spec_from for empty Vecs
21092112
vector.spec_extend(iterator);

0 commit comments

Comments
 (0)