@@ -29,7 +29,7 @@ use rustc::ty::{self, Ty, TyCtxt, ReprOptions, SymbolName};
29
29
use rustc:: ty:: codec:: { self as ty_codec, TyEncoder } ;
30
30
31
31
use rustc:: session:: config:: { self , CrateTypeProcMacro } ;
32
- use rustc:: util:: nodemap:: { FxHashMap , FxHashSet } ;
32
+ use rustc:: util:: nodemap:: FxHashMap ;
33
33
34
34
use rustc_data_structures:: stable_hasher:: StableHasher ;
35
35
use rustc_serialize:: { Encodable , Encoder , SpecializedEncoder , opaque} ;
@@ -62,7 +62,6 @@ pub struct EncodeContext<'a, 'tcx: 'a> {
62
62
63
63
interpret_allocs : FxHashMap < interpret:: AllocId , usize > ,
64
64
interpret_allocs_inverse : Vec < interpret:: AllocId > ,
65
- interpret_alloc_ids : FxHashSet < interpret:: AllocId > ,
66
65
67
66
// This is used to speed up Span encoding.
68
67
filemap_cache : Lrc < FileMap > ,
@@ -199,14 +198,15 @@ impl<'a, 'tcx> SpecializedEncoder<Ty<'tcx>> for EncodeContext<'a, 'tcx> {
199
198
200
199
impl < ' a , ' tcx > SpecializedEncoder < interpret:: AllocId > for EncodeContext < ' a , ' tcx > {
201
200
fn specialized_encode ( & mut self , alloc_id : & interpret:: AllocId ) -> Result < ( ) , Self :: Error > {
202
- let index = if self . interpret_alloc_ids . insert ( * alloc_id) {
203
- let idx = self . interpret_alloc_ids . len ( ) - 1 ;
204
- assert_eq ! ( idx, self . interpret_allocs_inverse. len( ) ) ;
205
- self . interpret_allocs_inverse . push ( * alloc_id) ;
206
- assert ! ( self . interpret_allocs. insert( * alloc_id, idx) . is_none( ) ) ;
207
- idx
208
- } else {
209
- self . interpret_allocs [ alloc_id]
201
+ use std:: collections:: hash_map:: Entry ;
202
+ let index = match self . interpret_allocs . entry ( * alloc_id) {
203
+ Entry :: Occupied ( e) => * e. get ( ) ,
204
+ Entry :: Vacant ( e) => {
205
+ let idx = self . interpret_allocs_inverse . len ( ) ;
206
+ self . interpret_allocs_inverse . push ( * alloc_id) ;
207
+ e. insert ( idx) ;
208
+ idx
209
+ } ,
210
210
} ;
211
211
212
212
index. encode ( self )
@@ -456,7 +456,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
456
456
let mut n = 0 ;
457
457
trace ! ( "beginning to encode alloc ids" ) ;
458
458
loop {
459
- let new_n = self . interpret_alloc_ids . len ( ) ;
459
+ let new_n = self . interpret_allocs_inverse . len ( ) ;
460
460
// if we have found new ids, serialize those, too
461
461
if n == new_n {
462
462
// otherwise, abort
@@ -487,7 +487,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
487
487
let is_proc_macro = tcx. sess . crate_types . borrow ( ) . contains ( & CrateTypeProcMacro ) ;
488
488
let has_default_lib_allocator =
489
489
attr:: contains_name ( tcx. hir . krate_attrs ( ) , "default_lib_allocator" ) ;
490
- let has_global_allocator = tcx. sess . has_global_allocator . get ( ) ;
490
+ let has_global_allocator = * tcx. sess . has_global_allocator . get ( ) ;
491
491
492
492
let root = self . lazy ( & CrateRoot {
493
493
name : tcx. crate_name ( LOCAL_CRATE ) ,
@@ -1792,7 +1792,6 @@ pub fn encode_metadata<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1792
1792
filemap_cache : tcx. sess . codemap ( ) . files ( ) [ 0 ] . clone ( ) ,
1793
1793
interpret_allocs : Default :: default ( ) ,
1794
1794
interpret_allocs_inverse : Default :: default ( ) ,
1795
- interpret_alloc_ids : Default :: default ( ) ,
1796
1795
} ;
1797
1796
1798
1797
// Encode the rustc version string in a predictable location.
0 commit comments