@@ -4,7 +4,7 @@ use crate::rmeta::*;
44use log:: { debug, trace} ;
55use rustc_ast:: ast;
66use rustc_data_structures:: fingerprint:: Fingerprint ;
7- use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
7+ use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexSet } ;
88use rustc_data_structures:: stable_hasher:: StableHasher ;
99use rustc_data_structures:: sync:: { join, Lrc } ;
1010use rustc_hir as hir;
@@ -48,8 +48,7 @@ struct EncodeContext<'a, 'tcx> {
4848 type_shorthands : FxHashMap < Ty < ' tcx > , usize > ,
4949 predicate_shorthands : FxHashMap < ty:: Predicate < ' tcx > , usize > ,
5050
51- interpret_allocs : FxHashMap < interpret:: AllocId , usize > ,
52- interpret_allocs_inverse : Vec < interpret:: AllocId > ,
51+ interpret_allocs : FxIndexSet < interpret:: AllocId > ,
5352
5453 // This is used to speed up Span encoding.
5554 // The `usize` is an index into the `MonotonicVec`
@@ -327,17 +326,7 @@ impl<'a, 'b, 'tcx> SpecializedEncoder<ty::Predicate<'b>> for EncodeContext<'a, '
327326
328327impl < ' a , ' tcx > SpecializedEncoder < interpret:: AllocId > for EncodeContext < ' a , ' tcx > {
329328 fn specialized_encode ( & mut self , alloc_id : & interpret:: AllocId ) -> Result < ( ) , Self :: Error > {
330- use std:: collections:: hash_map:: Entry ;
331- let index = match self . interpret_allocs . entry ( * alloc_id) {
332- Entry :: Occupied ( e) => * e. get ( ) ,
333- Entry :: Vacant ( e) => {
334- let idx = self . interpret_allocs_inverse . len ( ) ;
335- self . interpret_allocs_inverse . push ( * alloc_id) ;
336- e. insert ( idx) ;
337- idx
338- }
339- } ;
340-
329+ let ( index, _) = self . interpret_allocs . insert_full ( * alloc_id) ;
341330 index. encode ( self )
342331 }
343332}
@@ -579,15 +568,15 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
579568 let mut n = 0 ;
580569 trace ! ( "beginning to encode alloc ids" ) ;
581570 loop {
582- let new_n = self . interpret_allocs_inverse . len ( ) ;
571+ let new_n = self . interpret_allocs . len ( ) ;
583572 // if we have found new ids, serialize those, too
584573 if n == new_n {
585574 // otherwise, abort
586575 break ;
587576 }
588577 trace ! ( "encoding {} further alloc ids" , new_n - n) ;
589578 for idx in n..new_n {
590- let id = self . interpret_allocs_inverse [ idx] ;
579+ let id = self . interpret_allocs [ idx] ;
591580 let pos = self . position ( ) as u32 ;
592581 interpret_alloc_index. push ( pos) ;
593582 interpret:: specialized_encode_alloc_id ( self , tcx, id) . unwrap ( ) ;
@@ -2015,7 +2004,6 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>) -> EncodedMetadata {
20152004 predicate_shorthands : Default :: default ( ) ,
20162005 source_file_cache : ( source_map_files[ 0 ] . clone ( ) , 0 ) ,
20172006 interpret_allocs : Default :: default ( ) ,
2018- interpret_allocs_inverse : Default :: default ( ) ,
20192007 required_source_files : Some ( GrowableBitSet :: with_capacity ( source_map_files. len ( ) ) ) ,
20202008 is_proc_macro : tcx. sess . crate_types ( ) . contains ( & CrateType :: ProcMacro ) ,
20212009 hygiene_ctxt : & hygiene_ctxt,
0 commit comments