@@ -68,14 +68,15 @@ use util::nodemap::{NodeMap, NodeSet, DefIdMap, DefIdSet};
6868use util:: nodemap:: { FnvHashMap } ;
6969
7070use arena:: TypedArena ;
71- use std:: borrow:: BorrowFrom ;
71+ use std:: borrow:: { BorrowFrom , Cow } ;
7272use std:: cell:: { Cell , RefCell } ;
7373use std:: cmp:: { self , Ordering } ;
7474use std:: fmt:: { self , Show } ;
7575use std:: hash:: { Hash , Writer , SipHasher , Hasher } ;
7676use std:: mem;
7777use std:: ops;
7878use std:: rc:: Rc ;
79+ use std:: vec:: CowVec ;
7980use collections:: enum_set:: { EnumSet , CLike } ;
8081use std:: collections:: { HashMap , HashSet } ;
8182use syntax:: abi;
@@ -5555,40 +5556,20 @@ pub fn predicates<'tcx>(
55555556 vec
55565557}
55575558
5558- /// Iterate over attributes of a definition.
5559- // (This should really be an iterator, but that would require csearch and
5560- // decoder to use iterators instead of higher-order functions.)
5561- pub fn each_attr < F > ( tcx : & ctxt , did : DefId , mut f : F ) -> bool where
5562- F : FnMut ( & ast:: Attribute ) -> bool ,
5563- {
5559+ /// Get the attributes of a definition.
5560+ pub fn get_attrs < ' tcx > ( tcx : & ' tcx ctxt , did : DefId )
5561+ -> CowVec < ' tcx , ast:: Attribute > {
55645562 if is_local ( did) {
55655563 let item = tcx. map . expect_item ( did. node ) ;
5566- item. attrs . iter ( ) . all ( |attr| f ( attr ) )
5564+ Cow :: Borrowed ( & item. attrs [ ] )
55675565 } else {
5568- info ! ( "getting foreign attrs" ) ;
5569- let mut cont = true ;
5570- csearch:: get_item_attrs ( & tcx. sess . cstore , did, |attrs| {
5571- if cont {
5572- cont = attrs. iter ( ) . all ( |attr| f ( attr) ) ;
5573- }
5574- } ) ;
5575- info ! ( "done" ) ;
5576- cont
5566+ Cow :: Owned ( csearch:: get_item_attrs ( & tcx. sess . cstore , did) )
55775567 }
55785568}
55795569
55805570/// Determine whether an item is annotated with an attribute
55815571pub fn has_attr ( tcx : & ctxt , did : DefId , attr : & str ) -> bool {
5582- let mut found = false ;
5583- each_attr ( tcx, did, |item| {
5584- if item. check_name ( attr) {
5585- found = true ;
5586- false
5587- } else {
5588- true
5589- }
5590- } ) ;
5591- found
5572+ get_attrs ( tcx, did) . iter ( ) . any ( |item| item. check_name ( attr) )
55925573}
55935574
55945575/// Determine whether an item is annotated with `#[repr(packed)]`
@@ -5605,13 +5586,9 @@ pub fn lookup_simd(tcx: &ctxt, did: DefId) -> bool {
56055586pub fn lookup_repr_hints ( tcx : & ctxt , did : DefId ) -> Rc < Vec < attr:: ReprAttr > > {
56065587 memoized ( & tcx. repr_hint_cache , did, |did : DefId | {
56075588 Rc :: new ( if did. krate == LOCAL_CRATE {
5608- let mut acc = Vec :: new ( ) ;
5609- ty:: each_attr ( tcx, did, |meta| {
5610- acc. extend ( attr:: find_repr_attrs ( tcx. sess . diagnostic ( ) ,
5611- meta) . into_iter ( ) ) ;
5612- true
5613- } ) ;
5614- acc
5589+ get_attrs ( tcx, did) . iter ( ) . flat_map ( |meta| {
5590+ attr:: find_repr_attrs ( tcx. sess . diagnostic ( ) , meta) . into_iter ( )
5591+ } ) . collect ( )
56155592 } else {
56165593 csearch:: get_repr_attrs ( & tcx. sess . cstore , did)
56175594 } )
0 commit comments