@@ -4,7 +4,7 @@ use crate::rmeta::*;
4
4
use log:: { debug, trace} ;
5
5
use rustc_ast:: ast;
6
6
use rustc_data_structures:: fingerprint:: Fingerprint ;
7
- use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
7
+ use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexSet } ;
8
8
use rustc_data_structures:: stable_hasher:: StableHasher ;
9
9
use rustc_data_structures:: sync:: { join, Lrc } ;
10
10
use rustc_hir as hir;
@@ -48,8 +48,7 @@ struct EncodeContext<'a, 'tcx> {
48
48
type_shorthands : FxHashMap < Ty < ' tcx > , usize > ,
49
49
predicate_shorthands : FxHashMap < ty:: Predicate < ' tcx > , usize > ,
50
50
51
- interpret_allocs : FxHashMap < interpret:: AllocId , usize > ,
52
- interpret_allocs_inverse : Vec < interpret:: AllocId > ,
51
+ interpret_allocs : FxIndexSet < interpret:: AllocId > ,
53
52
54
53
// This is used to speed up Span encoding.
55
54
// The `usize` is an index into the `MonotonicVec`
@@ -327,17 +326,7 @@ impl<'a, 'b, 'tcx> SpecializedEncoder<ty::Predicate<'b>> for EncodeContext<'a, '
327
326
328
327
impl < ' a , ' tcx > SpecializedEncoder < interpret:: AllocId > for EncodeContext < ' a , ' tcx > {
329
328
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) ;
341
330
index. encode ( self )
342
331
}
343
332
}
@@ -579,15 +568,15 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
579
568
let mut n = 0 ;
580
569
trace ! ( "beginning to encode alloc ids" ) ;
581
570
loop {
582
- let new_n = self . interpret_allocs_inverse . len ( ) ;
571
+ let new_n = self . interpret_allocs . len ( ) ;
583
572
// if we have found new ids, serialize those, too
584
573
if n == new_n {
585
574
// otherwise, abort
586
575
break ;
587
576
}
588
577
trace ! ( "encoding {} further alloc ids" , new_n - n) ;
589
578
for idx in n..new_n {
590
- let id = self . interpret_allocs_inverse [ idx] ;
579
+ let id = self . interpret_allocs [ idx] ;
591
580
let pos = self . position ( ) as u32 ;
592
581
interpret_alloc_index. push ( pos) ;
593
582
interpret:: specialized_encode_alloc_id ( self , tcx, id) . unwrap ( ) ;
@@ -2015,7 +2004,6 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>) -> EncodedMetadata {
2015
2004
predicate_shorthands : Default :: default ( ) ,
2016
2005
source_file_cache : ( source_map_files[ 0 ] . clone ( ) , 0 ) ,
2017
2006
interpret_allocs : Default :: default ( ) ,
2018
- interpret_allocs_inverse : Default :: default ( ) ,
2019
2007
required_source_files : Some ( GrowableBitSet :: with_capacity ( source_map_files. len ( ) ) ) ,
2020
2008
is_proc_macro : tcx. sess . crate_types ( ) . contains ( & CrateType :: ProcMacro ) ,
2021
2009
hygiene_ctxt : & hygiene_ctxt,
0 commit comments