]> git.lizzy.rs Git - rust.git/commitdiff
nll: improve allocations
authorljedrz <ljedrz@gmail.com>
Wed, 17 Oct 2018 14:52:35 +0000 (16:52 +0200)
committerljedrz <ljedrz@gmail.com>
Wed, 17 Oct 2018 20:57:37 +0000 (22:57 +0200)
src/librustc_mir/borrow_check/nll/constraint_generation.rs
src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs
src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs

index 30b263a923a7fc3f06f041cbeaa7907fbb03ac4e..495e84528a3c3266d0eb8f9b34dba6158a00248a 100644 (file)
@@ -141,6 +141,7 @@ fn visit_assign(
         if let Some(all_facts) = self.all_facts {
             if let Place::Local(temp) = place {
                 if let Some(borrow_indices) = self.borrow_set.local_map.get(temp) {
+                    all_facts.killed.reserve(borrow_indices.len());
                     for &borrow_index in borrow_indices {
                         let location_index = self.location_table.mid_index(location);
                         all_facts.killed.push((borrow_index, location_index));
@@ -164,7 +165,9 @@ fn visit_terminator(
                 self.location_table.mid_index(location),
             ));
 
-            for successor_block in terminator.successors() {
+            let successor_blocks = terminator.successors();
+            all_facts.cfg_edge.reserve(successor_blocks.size_hint().0);
+            for successor_block in successor_blocks {
                 all_facts.cfg_edge.push((
                     self.location_table.mid_index(location),
                     self.location_table
index 307112f8ba16a26fb17dd4e4a482d4d2b5d96db7..a0ccfb8dc4c49702115fdbcf2ee7979f59c248d9 100644 (file)
@@ -279,9 +279,8 @@ fn is_borrow_location_in_loop(
                         pending_locations.push(target.start_location());
                     },
                     TerminatorKind::SwitchInt { ref targets, .. } => {
-                        for target in targets {
-                            pending_locations.push(target.start_location());
-                        }
+                        pending_locations.extend(
+                            targets.into_iter().map(|target| target.start_location()));
                     },
                     TerminatorKind::Drop { target, unwind, .. } |
                     TerminatorKind::DropAndReplace { target, unwind, .. } |
@@ -303,9 +302,8 @@ fn is_borrow_location_in_loop(
                     },
                     TerminatorKind::FalseEdges { real_target, ref imaginary_targets, .. } => {
                         pending_locations.push(real_target.start_location());
-                        for target in imaginary_targets {
-                            pending_locations.push(target.start_location());
-                        }
+                        pending_locations.extend(
+                            imaginary_targets.into_iter().map(|target| target.start_location()));
                     },
                     _ => {},
                 }
index 65ba2f537bf214c98982c05ce815e9b02bde5652..8d3cb7273181fdc1b68ab9473cbf853796770c7b 100644 (file)
@@ -462,9 +462,8 @@ fn give_name_if_we_can_match_hir_ty(
         argument_hir_ty: &hir::Ty,
         counter: &mut usize,
     ) -> Option<RegionName> {
-        let search_stack: &mut Vec<(Ty<'tcx>, &hir::Ty)> = &mut Vec::new();
-
-        search_stack.push((argument_ty, argument_hir_ty));
+        let search_stack: &mut Vec<(Ty<'tcx>, &hir::Ty)> =
+            &mut vec![(argument_ty, argument_hir_ty)];
 
         while let Some((ty, hir_ty)) = search_stack.pop() {
             match (&ty.sty, &hir_ty.node) {