22//! `Predecessors`/`PredecessorCache`.
33
44use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
5+ use rustc_data_structures:: stable_map:: FxHashMap ;
56use rustc_data_structures:: sync:: OnceCell ;
67use rustc_index:: vec:: IndexVec ;
78use rustc_serialize as serialize;
89use smallvec:: SmallVec ;
910
1011use crate :: mir:: { BasicBlock , BasicBlockData , Terminator , TerminatorKind } ;
1112
12- pub type SwitchSources = IndexVec < BasicBlock , IndexVec < BasicBlock , SmallVec < [ Option < u128 > ; 1 ] > > > ;
13+ pub type SwitchSources = FxHashMap < ( BasicBlock , BasicBlock ) , SmallVec < [ Option < u128 > ; 1 ] > > ;
1314
1415#[ derive( Clone , Debug ) ]
1516pub ( super ) struct SwitchSourceCache {
@@ -35,19 +36,16 @@ impl SwitchSourceCache {
3536 basic_blocks : & IndexVec < BasicBlock , BasicBlockData < ' _ > > ,
3637 ) -> & SwitchSources {
3738 self . cache . get_or_init ( || {
38- let mut switch_sources = IndexVec :: from_elem (
39- IndexVec :: from_elem ( SmallVec :: new ( ) , basic_blocks) ,
40- basic_blocks,
41- ) ;
39+ let mut switch_sources: SwitchSources = FxHashMap :: default ( ) ;
4240 for ( bb, data) in basic_blocks. iter_enumerated ( ) {
4341 if let Some ( Terminator {
4442 kind : TerminatorKind :: SwitchInt { targets, .. } , ..
4543 } ) = & data. terminator
4644 {
4745 for ( value, target) in targets. iter ( ) {
48- switch_sources[ target] [ bb ] . push ( Some ( value) ) ;
46+ switch_sources. entry ( ( target, bb ) ) . or_default ( ) . push ( Some ( value) ) ;
4947 }
50- switch_sources[ targets. otherwise ( ) ] [ bb ] . push ( None ) ;
48+ switch_sources. entry ( ( targets. otherwise ( ) , bb ) ) . or_default ( ) . push ( None ) ;
5149 }
5250 }
5351
0 commit comments