Skip to content

Commit 8ba2487

Browse files
committed
Adjust successor iterators.
Because rust-lang#148054 was a slight perf regression. The problem was seemingly because this iterator structure: ``` slice_iter.chain(Option_iter.chain(Option_iter)) ``` changed to this: ``` slice_iter.chain(Option_iter).chain(Option_iter) ``` The commit also tweaks the `slice_iter` part, changing `into_iter` to `iter` and using `[]` instead of `(&[])`, for conciseness and consistency.
1 parent f977dfc commit 8ba2487

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

compiler/rustc_middle/src/mir/terminator.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,8 @@ pub use helper::*;
501501

502502
mod helper {
503503
use super::*;
504-
// Note: the methods below use a `slice.chain(Option).chain(Option)` pattern so that all paths
505-
// produce an iterator with the same concrete type.
504+
// Note: the methods below use a `slice_iter.chain(option_iter.chain(option_iter))` pattern so
505+
// that all paths produce an iterator with the same concrete type.
506506
pub type Successors<'a> = impl DoubleEndedIterator<Item = BasicBlock> + 'a;
507507

508508
impl SwitchTargets {
@@ -512,7 +512,7 @@ mod helper {
512512
#[define_opaque(Successors)]
513513
pub fn successors_for_value(&self, value: u128) -> Successors<'_> {
514514
let target = self.target_for_value(value);
515-
(&[]).into_iter().copied().chain(Some(target)).chain(None)
515+
[].iter().copied().chain(Some(target).into_iter().chain(None))
516516
}
517517
}
518518

@@ -524,7 +524,7 @@ mod helper {
524524
match *self {
525525
// 3-successors for async drop: target, unwind, dropline (parent coroutine drop)
526526
Drop { target: ref t, unwind: UnwindAction::Cleanup(u), drop: Some(d), .. } => {
527-
slice::from_ref(t).into_iter().copied().chain(Some(u)).chain(Some(d))
527+
slice::from_ref(t).iter().copied().chain(Some(u).into_iter().chain(Some(d)))
528528
}
529529
// 2-successors
530530
Call { target: Some(ref t), unwind: UnwindAction::Cleanup(u), .. }
@@ -533,7 +533,7 @@ mod helper {
533533
| Drop { target: ref t, unwind: _, drop: Some(u), .. }
534534
| Assert { target: ref t, unwind: UnwindAction::Cleanup(u), .. }
535535
| FalseUnwind { real_target: ref t, unwind: UnwindAction::Cleanup(u) } => {
536-
slice::from_ref(t).into_iter().copied().chain(Some(u)).chain(None)
536+
slice::from_ref(t).iter().copied().chain(Some(u).into_iter().chain(None))
537537
}
538538
// single successor
539539
Goto { target: ref t }
@@ -543,7 +543,7 @@ mod helper {
543543
| Drop { target: ref t, unwind: _, .. }
544544
| Assert { target: ref t, unwind: _, .. }
545545
| FalseUnwind { real_target: ref t, unwind: _ } => {
546-
slice::from_ref(t).into_iter().copied().chain(None).chain(None)
546+
slice::from_ref(t).iter().copied().chain(None.into_iter().chain(None))
547547
}
548548
// No successors
549549
UnwindResume
@@ -553,24 +553,23 @@ mod helper {
553553
| Unreachable
554554
| TailCall { .. }
555555
| Call { target: None, unwind: _, .. } => {
556-
(&[]).into_iter().copied().chain(None).chain(None)
556+
[].iter().copied().chain(None.into_iter().chain(None))
557557
}
558558
// Multiple successors
559559
InlineAsm { ref targets, unwind: UnwindAction::Cleanup(u), .. } => {
560-
targets.iter().copied().chain(Some(u)).chain(None)
560+
targets.iter().copied().chain(Some(u).into_iter().chain(None))
561561
}
562562
InlineAsm { ref targets, unwind: _, .. } => {
563-
targets.iter().copied().chain(None).chain(None)
563+
targets.iter().copied().chain(None.into_iter().chain(None))
564564
}
565565
SwitchInt { ref targets, .. } => {
566-
targets.targets.iter().copied().chain(None).chain(None)
566+
targets.targets.iter().copied().chain(None.into_iter().chain(None))
567567
}
568568
// FalseEdge
569569
FalseEdge { ref real_target, imaginary_target } => slice::from_ref(real_target)
570-
.into_iter()
570+
.iter()
571571
.copied()
572-
.chain(Some(imaginary_target))
573-
.chain(None),
572+
.chain(Some(imaginary_target).into_iter().chain(None)),
574573
}
575574
}
576575

0 commit comments

Comments
 (0)