diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index edee439ad8d..36b7efc33a8 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -465,6 +465,7 @@ impl RawVec { // 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( new_layout: Result, current_memory: Option<(NonNull, Layout)>, diff --git a/library/alloc/src/vec.rs b/library/alloc/src/vec.rs index 9fffb47aa59..2b08f1f3629 100644 --- a/library/alloc/src/vec.rs +++ b/library/alloc/src/vec.rs @@ -2327,7 +2327,10 @@ where I: TrustedLen, { 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);