@@ -20,6 +20,7 @@ use hir::def::{Def, CtorKind, ExportMap};
20
20
use hir:: def_id:: { CrateNum , DefId , DefIndex , LocalDefId , CRATE_DEF_INDEX , LOCAL_CRATE } ;
21
21
use hir:: map:: DefPathData ;
22
22
use hir:: svh:: Svh ;
23
+ use ich:: Fingerprint ;
23
24
use ich:: StableHashingContext ;
24
25
use middle:: const_val:: ConstVal ;
25
26
use middle:: lang_items:: { FnTraitLangItem , FnMutTraitLangItem , FnOnceTraitLangItem } ;
@@ -37,6 +38,7 @@ use util::common::ErrorReported;
37
38
use util:: nodemap:: { NodeSet , DefIdMap , FxHashMap , FxHashSet } ;
38
39
39
40
use serialize:: { self , Encodable , Encoder } ;
41
+ use std:: cell:: RefCell ;
40
42
use std:: collections:: BTreeMap ;
41
43
use std:: cmp;
42
44
use std:: fmt;
@@ -1476,17 +1478,32 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for AdtDef {
1476
1478
fn hash_stable < W : StableHasherResult > ( & self ,
1477
1479
hcx : & mut StableHashingContext < ' gcx > ,
1478
1480
hasher : & mut StableHasher < W > ) {
1479
- let ty:: AdtDef {
1480
- did,
1481
- ref variants,
1482
- ref flags,
1483
- ref repr,
1484
- } = * self ;
1485
-
1486
- did. hash_stable ( hcx, hasher) ;
1487
- variants. hash_stable ( hcx, hasher) ;
1488
- flags. hash_stable ( hcx, hasher) ;
1489
- repr. hash_stable ( hcx, hasher) ;
1481
+ thread_local ! {
1482
+ static CACHE : RefCell <FxHashMap <usize , Fingerprint >> =
1483
+ RefCell :: new( FxHashMap ( ) ) ;
1484
+ }
1485
+
1486
+ let hash: Fingerprint = CACHE . with ( |cache| {
1487
+ let addr = self as * const AdtDef as usize ;
1488
+ * cache. borrow_mut ( ) . entry ( addr) . or_insert_with ( || {
1489
+ let ty:: AdtDef {
1490
+ did,
1491
+ ref variants,
1492
+ ref flags,
1493
+ ref repr,
1494
+ } = * self ;
1495
+
1496
+ let mut hasher = StableHasher :: new ( ) ;
1497
+ did. hash_stable ( hcx, & mut hasher) ;
1498
+ variants. hash_stable ( hcx, & mut hasher) ;
1499
+ flags. hash_stable ( hcx, & mut hasher) ;
1500
+ repr. hash_stable ( hcx, & mut hasher) ;
1501
+
1502
+ hasher. finish ( )
1503
+ } )
1504
+ } ) ;
1505
+
1506
+ hash. hash_stable ( hcx, hasher) ;
1490
1507
}
1491
1508
}
1492
1509
0 commit comments