Use slice.chain(option) for Successors

This makes more sense because most cases then second one is unwind target.
This commit is contained in:
Gary Guo 2023-12-26 04:31:56 +00:00
parent 040ab7d4b6
commit 7152993aa8

View File

@ -336,8 +336,7 @@ pub struct Terminator<'tcx> {
} }
pub type Successors<'a> = impl DoubleEndedIterator<Item = BasicBlock> + 'a; pub type Successors<'a> = impl DoubleEndedIterator<Item = BasicBlock> + 'a;
pub type SuccessorsMut<'a> = pub type SuccessorsMut<'a> = impl DoubleEndedIterator<Item = &'a mut BasicBlock> + 'a;
iter::Chain<std::option::IntoIter<&'a mut BasicBlock>, slice::IterMut<'a, BasicBlock>>;
impl<'tcx> Terminator<'tcx> { impl<'tcx> Terminator<'tcx> {
#[inline] #[inline]
@ -371,24 +370,24 @@ impl<'tcx> TerminatorKind<'tcx> {
pub fn successors(&self) -> Successors<'_> { pub fn successors(&self) -> Successors<'_> {
use self::TerminatorKind::*; use self::TerminatorKind::*;
match *self { match *self {
Call { target: Some(t), unwind: UnwindAction::Cleanup(ref u), .. } Call { target: Some(ref t), unwind: UnwindAction::Cleanup(u), .. }
| Yield { resume: t, drop: Some(ref u), .. } | Yield { resume: ref t, drop: Some(u), .. }
| Drop { target: t, unwind: UnwindAction::Cleanup(ref u), .. } | Drop { target: ref t, unwind: UnwindAction::Cleanup(u), .. }
| Assert { target: t, unwind: UnwindAction::Cleanup(ref u), .. } | Assert { target: ref t, unwind: UnwindAction::Cleanup(u), .. }
| FalseUnwind { real_target: t, unwind: UnwindAction::Cleanup(ref u) } | FalseUnwind { real_target: ref t, unwind: UnwindAction::Cleanup(u) }
| InlineAsm { destination: Some(t), unwind: UnwindAction::Cleanup(ref u), .. } => { | InlineAsm { destination: Some(ref t), unwind: UnwindAction::Cleanup(u), .. } => {
Some(t).into_iter().chain(slice::from_ref(u).into_iter().copied()) slice::from_ref(t).into_iter().copied().chain(Some(u))
} }
Goto { target: t } Goto { target: ref t }
| Call { target: None, unwind: UnwindAction::Cleanup(t), .. } | Call { target: None, unwind: UnwindAction::Cleanup(ref t), .. }
| Call { target: Some(t), unwind: _, .. } | Call { target: Some(ref t), unwind: _, .. }
| Yield { resume: t, drop: None, .. } | Yield { resume: ref t, drop: None, .. }
| Drop { target: t, unwind: _, .. } | Drop { target: ref t, unwind: _, .. }
| Assert { target: t, unwind: _, .. } | Assert { target: ref t, unwind: _, .. }
| FalseUnwind { real_target: t, unwind: _ } | FalseUnwind { real_target: ref t, unwind: _ }
| InlineAsm { destination: None, unwind: UnwindAction::Cleanup(t), .. } | InlineAsm { destination: None, unwind: UnwindAction::Cleanup(ref t), .. }
| InlineAsm { destination: Some(t), unwind: _, .. } => { | InlineAsm { destination: Some(ref t), unwind: _, .. } => {
Some(t).into_iter().chain((&[]).into_iter().copied()) slice::from_ref(t).into_iter().copied().chain(None)
} }
UnwindResume UnwindResume
| UnwindTerminate(_) | UnwindTerminate(_)
@ -397,14 +396,12 @@ impl<'tcx> TerminatorKind<'tcx> {
| Unreachable | Unreachable
| Call { target: None, unwind: _, .. } | Call { target: None, unwind: _, .. }
| InlineAsm { destination: None, unwind: _, .. } => { | InlineAsm { destination: None, unwind: _, .. } => {
None.into_iter().chain((&[]).into_iter().copied()) (&[]).into_iter().copied().chain(None)
} }
SwitchInt { ref targets, .. } => { SwitchInt { ref targets, .. } => targets.targets.iter().copied().chain(None),
None.into_iter().chain(targets.targets.iter().copied()) FalseEdge { ref real_target, imaginary_target } => {
slice::from_ref(real_target).into_iter().copied().chain(Some(imaginary_target))
} }
FalseEdge { real_target, ref imaginary_target } => Some(real_target)
.into_iter()
.chain(slice::from_ref(imaginary_target).into_iter().copied()),
} }
} }
@ -421,7 +418,7 @@ impl<'tcx> TerminatorKind<'tcx> {
destination: Some(ref mut t), destination: Some(ref mut t),
unwind: UnwindAction::Cleanup(ref mut u), unwind: UnwindAction::Cleanup(ref mut u),
.. ..
} => Some(t).into_iter().chain(slice::from_mut(u)), } => slice::from_mut(t).into_iter().chain(Some(u)),
Goto { target: ref mut t } Goto { target: ref mut t }
| Call { target: None, unwind: UnwindAction::Cleanup(ref mut t), .. } | Call { target: None, unwind: UnwindAction::Cleanup(ref mut t), .. }
| Call { target: Some(ref mut t), unwind: _, .. } | Call { target: Some(ref mut t), unwind: _, .. }
@ -431,7 +428,7 @@ impl<'tcx> TerminatorKind<'tcx> {
| FalseUnwind { real_target: ref mut t, unwind: _ } | FalseUnwind { real_target: ref mut t, unwind: _ }
| InlineAsm { destination: None, unwind: UnwindAction::Cleanup(ref mut t), .. } | InlineAsm { destination: None, unwind: UnwindAction::Cleanup(ref mut t), .. }
| InlineAsm { destination: Some(ref mut t), unwind: _, .. } => { | InlineAsm { destination: Some(ref mut t), unwind: _, .. } => {
Some(t).into_iter().chain(&mut []) slice::from_mut(t).into_iter().chain(None)
} }
UnwindResume UnwindResume
| UnwindTerminate(_) | UnwindTerminate(_)
@ -439,10 +436,10 @@ impl<'tcx> TerminatorKind<'tcx> {
| Return | Return
| Unreachable | Unreachable
| Call { target: None, unwind: _, .. } | Call { target: None, unwind: _, .. }
| InlineAsm { destination: None, unwind: _, .. } => None.into_iter().chain(&mut []), | InlineAsm { destination: None, unwind: _, .. } => (&mut []).into_iter().chain(None),
SwitchInt { ref mut targets, .. } => None.into_iter().chain(&mut targets.targets), SwitchInt { ref mut targets, .. } => targets.targets.iter_mut().chain(None),
FalseEdge { ref mut real_target, ref mut imaginary_target } => { FalseEdge { ref mut real_target, ref mut imaginary_target } => {
Some(real_target).into_iter().chain(slice::from_mut(imaginary_target)) slice::from_mut(real_target).into_iter().chain(Some(imaginary_target))
} }
} }
} }