@@ -30,7 +30,7 @@ impl<'tcx> Index<stable_mir::ty::Span> for Tables<'tcx> {
30
30
31
31
#[ inline( always) ]
32
32
fn index ( & self , index : stable_mir:: ty:: Span ) -> & Self :: Output {
33
- & self . spans [ index. 0 ]
33
+ & self . spans . get_index ( index. 0 ) . unwrap ( ) . 0
34
34
}
35
35
}
36
36
@@ -106,7 +106,6 @@ impl<'tcx> Tables<'tcx> {
106
106
}
107
107
108
108
fn create_alloc_id ( & mut self , aid : AllocId ) -> stable_mir:: AllocId {
109
- // FIXME: this becomes inefficient when we have too many ids
110
109
if let Some ( i) = self . alloc_ids . get ( & aid) {
111
110
return * i;
112
111
} else {
@@ -117,14 +116,13 @@ impl<'tcx> Tables<'tcx> {
117
116
}
118
117
119
118
pub ( crate ) fn create_span ( & mut self , span : Span ) -> stable_mir:: ty:: Span {
120
- for ( i, & sp) in self . spans . iter ( ) . enumerate ( ) {
121
- if sp == span {
122
- return stable_mir:: ty:: Span ( i) ;
123
- }
119
+ if let Some ( i) = self . spans . get ( & span) {
120
+ return * i;
121
+ } else {
122
+ let id = self . spans . len ( ) ;
123
+ self . spans . insert ( span, stable_mir:: ty:: Span ( id) ) ;
124
+ stable_mir:: ty:: Span ( id)
124
125
}
125
- let id = self . spans . len ( ) ;
126
- self . spans . push ( span) ;
127
- stable_mir:: ty:: Span ( id)
128
126
}
129
127
}
130
128
@@ -138,7 +136,7 @@ pub fn run(tcx: TyCtxt<'_>, f: impl FnOnce()) {
138
136
tcx,
139
137
def_ids : fx:: FxIndexMap :: default ( ) ,
140
138
alloc_ids : fx:: FxIndexMap :: default ( ) ,
141
- spans : vec ! [ ] ,
139
+ spans : fx :: FxIndexMap :: default ( ) ,
142
140
types : vec ! [ ] ,
143
141
} ,
144
142
f,
0 commit comments