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
2 changed files with 5 additions and 1 deletions
|
@ -471,6 +471,7 @@ impl<T, A: AllocRef> RawVec<T, A> {
|
||||||
// above `RawVec::grow_amortized` for details. (The `A` parameter isn't
|
// above `RawVec::grow_amortized` for details. (The `A` parameter isn't
|
||||||
// significant, because the number of different `A` types seen in practice is
|
// significant, because the number of different `A` types seen in practice is
|
||||||
// much smaller than the number of `T` types.)
|
// much smaller than the number of `T` types.)
|
||||||
|
#[inline(never)]
|
||||||
fn finish_grow<A>(
|
fn finish_grow<A>(
|
||||||
new_layout: Result<Layout, LayoutError>,
|
new_layout: Result<Layout, LayoutError>,
|
||||||
current_memory: Option<(NonNull<u8>, Layout)>,
|
current_memory: Option<(NonNull<u8>, Layout)>,
|
||||||
|
|
|
@ -2103,7 +2103,10 @@ where
|
||||||
I: TrustedLen<Item = T>,
|
I: TrustedLen<Item = T>,
|
||||||
{
|
{
|
||||||
fn from_iter(iterator: I) -> Self {
|
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
|
// must delegate to spec_extend() since extend() itself delegates
|
||||||
// to spec_from for empty Vecs
|
// to spec_from for empty Vecs
|
||||||
vector.spec_extend(iterator);
|
vector.spec_extend(iterator);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue