about summary refs log tree commit diff
path: root/library/alloc/src/vec.rs
diff options
context:
space:
mode:
Diffstat (limited to 'library/alloc/src/vec.rs')
-rw-r--r--library/alloc/src/vec.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/library/alloc/src/vec.rs b/library/alloc/src/vec.rs
index 2c8bc3d53ef..62398b82607 100644
--- a/library/alloc/src/vec.rs
+++ b/library/alloc/src/vec.rs
@@ -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);