]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/transform/simplify.rs
Rollup merge of #69949 - rust-lang:triagebot-ping-alias, r=Mark-Simulacrum
[rust.git] / src / librustc_mir / transform / simplify.rs
index d8de9f2180d64d9648aa3a34d21e6be4ab9ff454..4c54a46642f11e3cecd151357d03a050a3b26526 100644 (file)
@@ -95,6 +95,10 @@ pub fn simplify(mut self) {
 
         let mut start = START_BLOCK;
 
+        // Vec of the blocks that should be merged. We store the indices here, instead of the
+        // statements itself to avoid moving the (relatively) large statements twice.
+        // We do not push the statements directly into the target block (`bb`) as that is slower
+        // due to additional reallocations
         let mut merged_blocks = Vec::new();
         loop {
             let mut changed = false;
@@ -116,6 +120,7 @@ pub fn simplify(mut self) {
                 }
 
                 let mut inner_changed = true;
+                merged_blocks.clear();
                 while inner_changed {
                     inner_changed = false;
                     inner_changed |= self.simplify_branch(&mut terminator);
@@ -123,18 +128,17 @@ pub fn simplify(mut self) {
                     changed |= inner_changed;
                 }
 
-                let merged_block_count =
+                let statements_to_merge =
                     merged_blocks.iter().map(|&i| self.basic_blocks[i].statements.len()).sum();
 
-                if merged_block_count > 0 {
+                if statements_to_merge > 0 {
                     let mut statements = std::mem::take(&mut self.basic_blocks[bb].statements);
-                    statements.reserve(merged_block_count);
+                    statements.reserve(statements_to_merge);
                     for &from in &merged_blocks {
                         statements.append(&mut self.basic_blocks[from].statements);
                     }
                     self.basic_blocks[bb].statements = statements;
                 }
-                merged_blocks.clear();
 
                 self.basic_blocks[bb].terminator = Some(terminator);
 
@@ -242,7 +246,7 @@ fn simplify_branch(&mut self, terminator: &mut Terminator<'tcx>) -> bool {
         };
 
         let first_succ = {
-            if let Some(&first_succ) = terminator.successors().nth(0) {
+            if let Some(&first_succ) = terminator.successors().next() {
                 if terminator.successors().all(|s| *s == first_succ) {
                     let count = terminator.successors().count();
                     self.pred_count[first_succ] -= (count - 1) as u32;