Skip to content

Commit 9775861

Browse files
committed
Inline utils.
1 parent b509e2d commit 9775861

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

compiler/rustc_middle/src/mir/terminator.rs

+19
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ impl SwitchTargets {
2626
}
2727

2828
/// Inverse of `SwitchTargets::static_if`.
29+
#[inline]
2930
pub fn as_static_if(&self) -> Option<(u128, BasicBlock, BasicBlock)> {
3031
if let &[value] = &self.values[..]
3132
&& let &[then, else_] = &self.targets[..]
@@ -37,6 +38,7 @@ impl SwitchTargets {
3738
}
3839

3940
/// Returns the fallback target that is jumped to when none of the values match the operand.
41+
#[inline]
4042
pub fn otherwise(&self) -> BasicBlock {
4143
*self.targets.last().unwrap()
4244
}
@@ -47,22 +49,26 @@ impl SwitchTargets {
4749
/// including the `otherwise` fallback target.
4850
///
4951
/// Note that this may yield 0 elements. Only the `otherwise` branch is mandatory.
52+
#[inline]
5053
pub fn iter(&self) -> SwitchTargetsIter<'_> {
5154
SwitchTargetsIter { inner: iter::zip(&self.values, &self.targets) }
5255
}
5356

5457
/// Returns a slice with all possible jump targets (including the fallback target).
58+
#[inline]
5559
pub fn all_targets(&self) -> &[BasicBlock] {
5660
&self.targets
5761
}
5862

63+
#[inline]
5964
pub fn all_targets_mut(&mut self) -> &mut [BasicBlock] {
6065
&mut self.targets
6166
}
6267

6368
/// Finds the `BasicBlock` to which this `SwitchInt` will branch given the
6469
/// specific value. This cannot fail, as it'll return the `otherwise`
6570
/// branch if there's not a specific match for the value.
71+
#[inline]
6672
pub fn target_for_value(&self, value: u128) -> BasicBlock {
6773
self.iter().find_map(|(v, t)| (v == value).then_some(t)).unwrap_or_else(|| self.otherwise())
6874
}
@@ -75,10 +81,12 @@ pub struct SwitchTargetsIter<'a> {
7581
impl<'a> Iterator for SwitchTargetsIter<'a> {
7682
type Item = (u128, BasicBlock);
7783

84+
#[inline]
7885
fn next(&mut self) -> Option<Self::Item> {
7986
self.inner.next().map(|(val, bb)| (*val, *bb))
8087
}
8188

89+
#[inline]
8290
fn size_hint(&self) -> (usize, Option<usize>) {
8391
self.inner.size_hint()
8492
}
@@ -330,28 +338,34 @@ pub type SuccessorsMut<'a> =
330338
iter::Chain<std::option::IntoIter<&'a mut BasicBlock>, slice::IterMut<'a, BasicBlock>>;
331339

332340
impl<'tcx> Terminator<'tcx> {
341+
#[inline]
333342
pub fn successors(&self) -> Successors<'_> {
334343
self.kind.successors()
335344
}
336345

346+
#[inline]
337347
pub fn successors_mut(&mut self) -> SuccessorsMut<'_> {
338348
self.kind.successors_mut()
339349
}
340350

351+
#[inline]
341352
pub fn unwind(&self) -> Option<&UnwindAction> {
342353
self.kind.unwind()
343354
}
344355

356+
#[inline]
345357
pub fn unwind_mut(&mut self) -> Option<&mut UnwindAction> {
346358
self.kind.unwind_mut()
347359
}
348360
}
349361

350362
impl<'tcx> TerminatorKind<'tcx> {
363+
#[inline]
351364
pub fn if_(cond: Operand<'tcx>, t: BasicBlock, f: BasicBlock) -> TerminatorKind<'tcx> {
352365
TerminatorKind::SwitchInt { discr: cond, targets: SwitchTargets::static_if(0, f, t) }
353366
}
354367

368+
#[inline]
355369
pub fn successors(&self) -> Successors<'_> {
356370
use self::TerminatorKind::*;
357371
match *self {
@@ -392,6 +406,7 @@ impl<'tcx> TerminatorKind<'tcx> {
392406
}
393407
}
394408

409+
#[inline]
395410
pub fn successors_mut(&mut self) -> SuccessorsMut<'_> {
396411
use self::TerminatorKind::*;
397412
match *self {
@@ -430,6 +445,7 @@ impl<'tcx> TerminatorKind<'tcx> {
430445
}
431446
}
432447

448+
#[inline]
433449
pub fn unwind(&self) -> Option<&UnwindAction> {
434450
match *self {
435451
TerminatorKind::Goto { .. }
@@ -449,6 +465,7 @@ impl<'tcx> TerminatorKind<'tcx> {
449465
}
450466
}
451467

468+
#[inline]
452469
pub fn unwind_mut(&mut self) -> Option<&mut UnwindAction> {
453470
match *self {
454471
TerminatorKind::Goto { .. }
@@ -468,13 +485,15 @@ impl<'tcx> TerminatorKind<'tcx> {
468485
}
469486
}
470487

488+
#[inline]
471489
pub fn as_switch(&self) -> Option<(&Operand<'tcx>, &SwitchTargets)> {
472490
match self {
473491
TerminatorKind::SwitchInt { discr, targets } => Some((discr, targets)),
474492
_ => None,
475493
}
476494
}
477495

496+
#[inline]
478497
pub fn as_goto(&self) -> Option<BasicBlock> {
479498
match self {
480499
TerminatorKind::Goto { target } => Some(*target),

0 commit comments

Comments
 (0)