diff --git a/src/librustc/middle/dataflow.rs b/src/librustc/middle/dataflow.rs index 5c86554f90790..681bf6b4fcff4 100644 --- a/src/librustc/middle/dataflow.rs +++ b/src/librustc/middle/dataflow.rs @@ -181,7 +181,7 @@ fn build_local_id_to_index(body: Option<&hir::Body>, cfg.graph.each_node(|node_idx, node| { if let cfg::CFGNodeData::AST(id) = node.data { - index.entry(id).or_insert(vec![]).push(node_idx); + index.entry(id).or_insert_with(|| Vec::with_capacity(1)).push(node_idx); } true }); @@ -209,7 +209,8 @@ fn build_local_id_to_index(body: Option<&hir::Body>, } fn visit_pat(&mut self, p: &hir::Pat) { - self.index.entry(p.hir_id.local_id).or_insert(vec![]).push(self.entry); + self.index.entry(p.hir_id.local_id) + .or_insert_with(|| Vec::with_capacity(1)).push(self.entry); intravisit::walk_pat(self, p) } } diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs index bfa32f8e7faf3..95cf78f03ca33 100644 --- a/src/librustc/traits/project.rs +++ b/src/librustc/traits/project.rs @@ -597,7 +597,11 @@ fn opt_normalize_projection_type<'a, 'b, 'gcx, 'tcx>( // can ignore the `obligations` from that point on. if !infcx.any_unresolved_type_vars(&ty.value) { infcx.projection_cache.borrow_mut().complete(cache_key); - ty.obligations = vec![]; + // Use with_capacity(1) because + // push_paranoid_cache_value_obligation() will push one + // element, and then usually no more elements are pushed. + // (Vec::new() + push() gives a capacity of 4.) + ty.obligations = Vec::with_capacity(1); } push_paranoid_cache_value_obligation(infcx,