2
2
//! `Predecessors`/`PredecessorCache`.
3
3
4
4
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
5
+ use rustc_data_structures:: stable_map:: FxHashMap ;
5
6
use rustc_data_structures:: sync:: OnceCell ;
6
7
use rustc_index:: vec:: IndexVec ;
7
8
use rustc_serialize as serialize;
8
9
use smallvec:: SmallVec ;
9
10
10
11
use crate :: mir:: { BasicBlock , BasicBlockData , Terminator , TerminatorKind } ;
11
12
12
- pub type SwitchSources = IndexVec < BasicBlock , IndexVec < BasicBlock , SmallVec < [ Option < u128 > ; 1 ] > > > ;
13
+ pub type SwitchSources = FxHashMap < ( BasicBlock , BasicBlock ) , SmallVec < [ Option < u128 > ; 1 ] > > ;
13
14
14
15
#[ derive( Clone , Debug ) ]
15
16
pub ( super ) struct SwitchSourceCache {
@@ -35,19 +36,16 @@ impl SwitchSourceCache {
35
36
basic_blocks : & IndexVec < BasicBlock , BasicBlockData < ' _ > > ,
36
37
) -> & SwitchSources {
37
38
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 ( ) ;
42
40
for ( bb, data) in basic_blocks. iter_enumerated ( ) {
43
41
if let Some ( Terminator {
44
42
kind : TerminatorKind :: SwitchInt { targets, .. } , ..
45
43
} ) = & data. terminator
46
44
{
47
45
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) ) ;
49
47
}
50
- switch_sources[ targets. otherwise ( ) ] [ bb ] . push ( None ) ;
48
+ switch_sources. entry ( ( targets. otherwise ( ) , bb ) ) . or_default ( ) . push ( None ) ;
51
49
}
52
50
}
53
51
0 commit comments