about summary refs log tree commit diff
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
parent7e8ca9f8bd8325398e76bc30ac09aab138bbb127 (diff)
downloadrust-b68b3965a241e47c232613f403fbace64fd8b876.tar.gz
rust-b68b3965a241e47c232613f403fbace64fd8b876.zip
Don't collect() when size_hint is useless
-rw-r--r--src/librustc/infer/outlives/obligations.rs12
-rw-r--r--src/librustc_data_structures/small_vec.rs7
-rw-r--r--src/libsyntax/ast.rs6
3 files changed, 18 insertions, 7 deletions
diff --git a/src/librustc/infer/outlives/obligations.rs b/src/librustc/infer/outlives/obligations.rs
index c74783f5e4d..3598d66060b 100644
--- a/src/librustc/infer/outlives/obligations.rs
+++ b/src/librustc/infer/outlives/obligations.rs
@@ -151,12 +151,14 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
         debug!("process_registered_region_obligations()");
 
         // pull out the region obligations with the given `body_id` (leaving the rest)
-        let my_region_obligations = {
+        let mut my_region_obligations = Vec::with_capacity(self.region_obligations.borrow().len());
+        {
             let mut r_o = self.region_obligations.borrow_mut();
-            let my_r_o = r_o.drain_filter(|(ro_body_id, _)| *ro_body_id == body_id)
-                            .map(|(_, obligation)| obligation).collect::<Vec<_>>();
-            my_r_o
-        };
+            my_region_obligations.extend(
+                r_o.drain_filter(|(ro_body_id, _)| *ro_body_id == body_id)
+                   .map(|(_, obligation)| obligation)
+            );
+        }
 
         let outlives = &mut TypeOutlives::new(
             self,
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)
         })
     }
 }
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 28c1e4324de..6925ed2afb8 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -501,7 +501,11 @@ impl Pat {
             PatKind::Slice(pats, None, _) if pats.len() == 1 =>
                 pats[0].to_ty().map(TyKind::Slice)?,
             PatKind::Tuple(pats, None) => {
-                let tys = pats.iter().map(|pat| pat.to_ty()).collect::<Option<Vec<_>>>()?;
+                let mut tys = Vec::with_capacity(pats.len());
+                // FIXME(#48994) - could just be collected into an Option<Vec>
+                for pat in pats {
+                    tys.push(pat.to_ty()?);
+                }
                 TyKind::Tup(tys)
             }
             _ => return None,