Skip to content

Commit eaa8f06

Browse files
committed
transmutability: merge contiguous runs with a common destination
1 parent 88a8679 commit eaa8f06

File tree

1 file changed

+15
-3
lines changed
  • compiler/rustc_transmute/src/layout

1 file changed

+15
-3
lines changed

compiler/rustc_transmute/src/layout/dfa.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,24 @@ mod edge_set {
401401
mut join: impl FnMut(Option<S>, Option<S>) -> S,
402402
) -> EdgeSet<S>
403403
where
404-
S: Copy,
404+
S: Copy + Eq,
405405
{
406+
let mut runs: SmallVec<[(Byte, S); 1]> = SmallVec::new();
406407
let xs = self.runs.iter().copied();
407408
let ys = other.runs.iter().copied();
408-
// FIXME(@joshlf): Merge contiguous runs with common destination.
409-
EdgeSet { runs: union(xs, ys).map(|(range, (x, y))| (range, join(x, y))).collect() }
409+
for (range, (x, y)) in union(xs, ys) {
410+
let state = join(x, y);
411+
match runs.last_mut() {
412+
// Merge contiguous runs with a common destination.
413+
Some(&mut (ref mut last_range, ref mut last_state))
414+
if last_range.end == range.start && *last_state == state =>
415+
{
416+
last_range.end = range.end
417+
}
418+
_ => runs.push((range, state)),
419+
}
420+
}
421+
EdgeSet { runs }
410422
}
411423
}
412424
}

0 commit comments

Comments
 (0)