@@ -583,6 +583,9 @@ pub struct ctxt<'tcx> {
583583 /// Caches the results of trait selection. This cache is used
584584 /// for things that do not have to do with the parameters in scope.
585585 pub selection_cache : traits:: SelectionCache ,
586+
587+ /// Caches the representation hints for struct definitions.
588+ pub repr_hint_cache : RefCell < DefIdMap < Rc < Vec < attr:: ReprAttr > > > > ,
586589}
587590
588591pub enum tbox_flag {
@@ -1533,6 +1536,7 @@ pub fn mk_ctxt<'tcx>(s: Session,
15331536 associated_types : RefCell :: new ( DefIdMap :: new ( ) ) ,
15341537 trait_associated_types : RefCell :: new ( DefIdMap :: new ( ) ) ,
15351538 selection_cache : traits:: SelectionCache :: new ( ) ,
1539+ repr_hint_cache : RefCell :: new ( DefIdMap :: new ( ) ) ,
15361540 }
15371541}
15381542
@@ -4326,7 +4330,7 @@ pub fn ty_dtor(cx: &ctxt, struct_id: DefId) -> DtorKind {
43264330}
43274331
43284332pub fn has_dtor ( cx : & ctxt , struct_id : DefId ) -> bool {
4329- ty_dtor ( cx , struct_id ) . is_present ( )
4333+ cx . destructor_for_type . borrow ( ) . contains_key ( & struct_id )
43304334}
43314335
43324336pub fn with_path < T > ( cx : & ctxt , id : ast:: DefId , f: |ast_map:: PathElems | -> T ) -> T {
@@ -4513,14 +4517,26 @@ pub fn lookup_simd(tcx: &ctxt, did: DefId) -> bool {
45134517}
45144518
45154519/// Obtain the representation annotation for a struct definition.
4516- pub fn lookup_repr_hints ( tcx : & ctxt , did : DefId ) -> Vec < attr:: ReprAttr > {
4517- let mut acc = Vec :: new ( ) ;
4520+ pub fn lookup_repr_hints ( tcx : & ctxt , did : DefId ) -> Rc < Vec < attr:: ReprAttr > > {
4521+ match tcx. repr_hint_cache . borrow ( ) . find ( & did) {
4522+ None => { }
4523+ Some ( ref hints) => return ( * hints) . clone ( ) ,
4524+ }
45184525
4519- ty:: each_attr ( tcx, did, |meta| {
4520- acc. extend ( attr:: find_repr_attrs ( tcx. sess . diagnostic ( ) , meta) . into_iter ( ) ) ;
4521- true
4522- } ) ;
4526+ let acc = if did. krate == LOCAL_CRATE {
4527+ let mut acc = Vec :: new ( ) ;
4528+ ty:: each_attr ( tcx, did, |meta| {
4529+ acc. extend ( attr:: find_repr_attrs ( tcx. sess . diagnostic ( ) ,
4530+ meta) . into_iter ( ) ) ;
4531+ true
4532+ } ) ;
4533+ acc
4534+ } else {
4535+ csearch:: get_repr_attrs ( & tcx. sess . cstore , did)
4536+ } ;
45234537
4538+ let acc = Rc :: new ( acc) ;
4539+ tcx. repr_hint_cache . borrow_mut ( ) . insert ( did, acc. clone ( ) ) ;
45244540 acc
45254541}
45264542
0 commit comments