about summary refs log tree commit diff
path: root/src/librustc_data_structures
diff options
context:
space:
mode:
authorljedrz <ljedrz@gmail.com>2018-08-03 10:19:22 +0200
committerljedrz <ljedrz@gmail.com>2018-08-03 10:19:22 +0200
commitb68b3965a241e47c232613f403fbace64fd8b876 (patch)
treef08775c6ea1e22d20212a459aa7774c8b2fe8786 /src/librustc_data_structures
parent7e8ca9f8bd8325398e76bc30ac09aab138bbb127 (diff)
Don't collect() when size_hint is useless
Diffstat (limited to 'src/librustc_data_structures')
-rw-r--r--src/librustc_data_structures/small_vec.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/librustc_data_structures/small_vec.rs b/src/librustc_data_structures/small_vec.rs
index 76b01beb4ba..e958fd7da61 100644
--- a/src/librustc_data_structures/small_vec.rs
+++ b/src/librustc_data_structures/small_vec.rs
@@ -210,7 +210,12 @@ impl<A> Decodable for SmallVec<A>
           A::Element: Decodable {
     fn decode<D: Decoder>(d: &mut D) -> Result<SmallVec<A>, D::Error> {
         d.read_seq(|d, len| {
-            (0..len).map(|i| d.read_seq_elt(i, |d| Decodable::decode(d))).collect()
+            let mut vec = SmallVec::with_capacity(len);
+            // FIXME(#48994) - could just be collected into a Result<SmallVec, D::Error>
+            for i in 0..len {
+                vec.push(d.read_seq_elt(i, |d| Decodable::decode(d))?);
+            }
+            Ok(vec)
         })
     }
 }