about summary refs log tree commit diff
path: root/library/alloc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-12-15 06:32:10 +0000
committerbors <bors@rust-lang.org>2020-12-15 06:32:10 +0000
commite261649593cf9c2707f7b30a61c46c4469c67ebb (patch)
tree4532de1ee4809a9894d5234f1767ed14ed296f44 /library/alloc
parente1cce06e4ff5206daf397e1dcf91ed53653be171 (diff)
parent76bd14548910a13049b59b14e09a80cfd3a29b77 (diff)
downloadrust-e261649593cf9c2707f7b30a61c46c4469c67ebb.tar.gz
rust-e261649593cf9c2707f7b30a61c46c4469c67ebb.zip
Auto merge of #78682 - glandium:issue78471, r=lcnr
Do not inline finish_grow

Fixes #78471.

Looking at libgkrust.a in Firefox, the sizes for the `gkrust.*.o` file is:
- 18584816 (text) 582418 (data) with unmodified master
- 17937659 (text) 582554 (data) with #72227 reverted
- 17968228 (text) 582858 (data) with `#[inline(never)]` on `grow_amortized` and `grow_exact`, but that has some performance consequences
- 17927760 (text) 582322 (data) with this change

So in terms of size, at least in the case of Firefox, this patch more than undoes the regression. I don't think it should affect performance, but we'll see.
Diffstat (limited to 'library/alloc')
-rw-r--r--library/alloc/src/raw_vec.rs1
-rw-r--r--library/alloc/src/vec.rs5
2 files changed, 5 insertions, 1 deletions
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<T, A: Allocator> 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)>,
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<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);