@@ -29,7 +29,7 @@ use rustc::ty::{self, Ty, TyCtxt, ReprOptions, SymbolName};
2929use rustc:: ty:: codec:: { self as ty_codec, TyEncoder } ;
3030
3131use rustc:: session:: config:: { self , CrateTypeProcMacro } ;
32- use rustc:: util:: nodemap:: { FxHashMap , FxHashSet } ;
32+ use rustc:: util:: nodemap:: FxHashMap ;
3333
3434use rustc_data_structures:: stable_hasher:: StableHasher ;
3535use rustc_serialize:: { Encodable , Encoder , SpecializedEncoder , opaque} ;
@@ -62,7 +62,6 @@ pub struct EncodeContext<'a, 'tcx: 'a> {
6262
6363 interpret_allocs : FxHashMap < interpret:: AllocId , usize > ,
6464 interpret_allocs_inverse : Vec < interpret:: AllocId > ,
65- interpret_alloc_ids : FxHashSet < interpret:: AllocId > ,
6665
6766 // This is used to speed up Span encoding.
6867 filemap_cache : Lrc < FileMap > ,
@@ -199,14 +198,15 @@ impl<'a, 'tcx> SpecializedEncoder<Ty<'tcx>> for EncodeContext<'a, 'tcx> {
199198
200199impl < ' a , ' tcx > SpecializedEncoder < interpret:: AllocId > for EncodeContext < ' a , ' tcx > {
201200 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+ } ,
210210 } ;
211211
212212 index. encode ( self )
@@ -456,7 +456,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
456456 let mut n = 0 ;
457457 trace ! ( "beginning to encode alloc ids" ) ;
458458 loop {
459- let new_n = self . interpret_alloc_ids . len ( ) ;
459+ let new_n = self . interpret_allocs_inverse . len ( ) ;
460460 // if we have found new ids, serialize those, too
461461 if n == new_n {
462462 // otherwise, abort
@@ -487,7 +487,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
487487 let is_proc_macro = tcx. sess . crate_types . borrow ( ) . contains ( & CrateTypeProcMacro ) ;
488488 let has_default_lib_allocator =
489489 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 ( ) ;
491491
492492 let root = self . lazy ( & CrateRoot {
493493 name : tcx. crate_name ( LOCAL_CRATE ) ,
@@ -1786,7 +1786,6 @@ pub fn encode_metadata<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
17861786 filemap_cache : tcx. sess . codemap ( ) . files ( ) [ 0 ] . clone ( ) ,
17871787 interpret_allocs : Default :: default ( ) ,
17881788 interpret_allocs_inverse : Default :: default ( ) ,
1789- interpret_alloc_ids : Default :: default ( ) ,
17901789 } ;
17911790
17921791 // Encode the rustc version string in a predictable location.
0 commit comments