@@ -5,7 +5,7 @@ use crate::ty::codec::{self as ty_codec, TyDecoder, TyEncoder};
5
5
use crate :: ty:: context:: TyCtxt ;
6
6
use crate :: ty:: { self , Ty } ;
7
7
use rustc_data_structures:: fingerprint:: Fingerprint ;
8
- use rustc_data_structures:: fx:: FxHashMap ;
8
+ use rustc_data_structures:: fx:: { FxHashMap , FxIndexSet } ;
9
9
use rustc_data_structures:: sync:: { HashMapExt , Lock , Lrc , OnceCell } ;
10
10
use rustc_data_structures:: thin_vec:: ThinVec ;
11
11
use rustc_errors:: Diagnostic ;
@@ -212,7 +212,6 @@ impl<'sess> OnDiskCache<'sess> {
212
212
type_shorthands : Default :: default ( ) ,
213
213
predicate_shorthands : Default :: default ( ) ,
214
214
interpret_allocs : Default :: default ( ) ,
215
- interpret_allocs_inverse : Vec :: new ( ) ,
216
215
source_map : CachingSourceMapView :: new ( tcx. sess . source_map ( ) ) ,
217
216
file_to_file_index,
218
217
hygiene_context : & hygiene_encode_context,
@@ -267,15 +266,15 @@ impl<'sess> OnDiskCache<'sess> {
267
266
let mut interpret_alloc_index = Vec :: new ( ) ;
268
267
let mut n = 0 ;
269
268
loop {
270
- let new_n = encoder. interpret_allocs_inverse . len ( ) ;
269
+ let new_n = encoder. interpret_allocs . len ( ) ;
271
270
// If we have found new IDs, serialize those too.
272
271
if n == new_n {
273
272
// Otherwise, abort.
274
273
break ;
275
274
}
276
275
interpret_alloc_index. reserve ( new_n - n) ;
277
276
for idx in n..new_n {
278
- let id = encoder. interpret_allocs_inverse [ idx] ;
277
+ let id = encoder. interpret_allocs [ idx] ;
279
278
let pos = encoder. position ( ) as u32 ;
280
279
interpret_alloc_index. push ( pos) ;
281
280
interpret:: specialized_encode_alloc_id ( & mut encoder, tcx, id) ?;
@@ -767,8 +766,7 @@ struct CacheEncoder<'a, 'tcx, E: ty_codec::TyEncoder> {
767
766
encoder : & ' a mut E ,
768
767
type_shorthands : FxHashMap < Ty < ' tcx > , usize > ,
769
768
predicate_shorthands : FxHashMap < ty:: Predicate < ' tcx > , usize > ,
770
- interpret_allocs : FxHashMap < interpret:: AllocId , usize > ,
771
- interpret_allocs_inverse : Vec < interpret:: AllocId > ,
769
+ interpret_allocs : FxIndexSet < interpret:: AllocId > ,
772
770
source_map : CachingSourceMapView < ' tcx > ,
773
771
file_to_file_index : FxHashMap < * const SourceFile , SourceFileIndex > ,
774
772
hygiene_context : & ' a HygieneEncodeContext ,
@@ -807,17 +805,7 @@ where
807
805
E : ' a + TyEncoder ,
808
806
{
809
807
fn specialized_encode ( & mut self , alloc_id : & interpret:: AllocId ) -> Result < ( ) , Self :: Error > {
810
- use std:: collections:: hash_map:: Entry ;
811
- let index = match self . interpret_allocs . entry ( * alloc_id) {
812
- Entry :: Occupied ( e) => * e. get ( ) ,
813
- Entry :: Vacant ( e) => {
814
- let idx = self . interpret_allocs_inverse . len ( ) ;
815
- self . interpret_allocs_inverse . push ( * alloc_id) ;
816
- e. insert ( idx) ;
817
- idx
818
- }
819
- } ;
820
-
808
+ let ( index, _) = self . interpret_allocs . insert_full ( * alloc_id) ;
821
809
index. encode ( self )
822
810
}
823
811
}
0 commit comments