@@ -30,7 +30,7 @@ impl<'tcx> Index<stable_mir::ty::Span> for Tables<'tcx> {
3030
3131 #[ inline( always) ]
3232 fn index ( & self , index : stable_mir:: ty:: Span ) -> & Self :: Output {
33- & self . spans [ index. 0 ]
33+ & self . spans . get_index ( index. 0 ) . unwrap ( ) . 0
3434 }
3535}
3636
@@ -106,7 +106,6 @@ impl<'tcx> Tables<'tcx> {
106106 }
107107
108108 fn create_alloc_id ( & mut self , aid : AllocId ) -> stable_mir:: AllocId {
109- // FIXME: this becomes inefficient when we have too many ids
110109 if let Some ( i) = self . alloc_ids . get ( & aid) {
111110 return * i;
112111 } else {
@@ -117,14 +116,13 @@ impl<'tcx> Tables<'tcx> {
117116 }
118117
119118 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)
124125 }
125- let id = self . spans . len ( ) ;
126- self . spans . push ( span) ;
127- stable_mir:: ty:: Span ( id)
128126 }
129127}
130128
@@ -138,7 +136,7 @@ pub fn run(tcx: TyCtxt<'_>, f: impl FnOnce()) {
138136 tcx,
139137 def_ids : fx:: FxIndexMap :: default ( ) ,
140138 alloc_ids : fx:: FxIndexMap :: default ( ) ,
141- spans : vec ! [ ] ,
139+ spans : fx :: FxIndexMap :: default ( ) ,
142140 types : vec ! [ ] ,
143141 } ,
144142 f,
0 commit comments