Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion compiler/rustc_middle/src/mir/terminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ impl SwitchTargets {
/// branch if there's not a specific match for the value.
#[inline]
pub fn target_for_value(&self, value: u128) -> BasicBlock {
self.iter().find_map(|(v, t)| (v == value).then_some(t)).unwrap_or_else(|| self.otherwise())
let value = Pu128(value);
if let Some(idx) = self.values.iter().position(|&v| v == value) {
// SAFETY: Invariant ensures targets.len() == values.len() + 1.
// If index is in values, it is valid in targets.
unsafe { *self.targets.get_unchecked(idx) }
} else {
self.otherwise()
}
}

/// Adds a new target to the switch. Panics if you add an already present value.
Expand Down
Loading