@@ -44,21 +44,18 @@ impl RawAttrs {
4444 owner : & dyn ast:: HasAttrs ,
4545 span_map : SpanMapRef < ' _ > ,
4646 ) -> Self {
47- let entries = collect_attrs ( owner)
48- . filter_map ( |( id, attr) | match attr {
49- Either :: Left ( attr) => {
50- attr. meta ( ) . and_then ( |meta| Attr :: from_src ( db, meta, span_map, id) )
51- }
52- Either :: Right ( comment) => comment. doc_comment ( ) . map ( |doc| Attr {
53- id,
54- input : Some ( Interned :: new ( AttrInput :: Literal ( SmolStr :: new ( doc) ) ) ) ,
55- path : Interned :: new ( ModPath :: from ( crate :: name!( doc) ) ) ,
56- ctxt : span_map. span_for_range ( comment. syntax ( ) . text_range ( ) ) . ctx ,
57- } ) ,
58- } )
59- . collect :: < Vec < _ > > ( ) ;
60- // FIXME: use `Arc::from_iter` when it becomes available
61- let entries: Arc < [ Attr ] > = Arc :: from ( entries) ;
47+ let entries = collect_attrs ( owner) . filter_map ( |( id, attr) | match attr {
48+ Either :: Left ( attr) => {
49+ attr. meta ( ) . and_then ( |meta| Attr :: from_src ( db, meta, span_map, id) )
50+ }
51+ Either :: Right ( comment) => comment. doc_comment ( ) . map ( |doc| Attr {
52+ id,
53+ input : Some ( Interned :: new ( AttrInput :: Literal ( SmolStr :: new ( doc) ) ) ) ,
54+ path : Interned :: new ( ModPath :: from ( crate :: name!( doc) ) ) ,
55+ ctxt : span_map. span_for_range ( comment. syntax ( ) . text_range ( ) ) . ctx ,
56+ } ) ,
57+ } ) ;
58+ let entries: Arc < [ Attr ] > = Arc :: from_iter ( entries) ;
6259
6360 Self { entries : if entries. is_empty ( ) { None } else { Some ( entries) } }
6461 }
@@ -79,19 +76,13 @@ impl RawAttrs {
7976 ( Some ( a) , Some ( b) ) => {
8077 let last_ast_index = a. last ( ) . map_or ( 0 , |it| it. id . ast_index ( ) + 1 ) as u32 ;
8178 Self {
82- entries : Some ( Arc :: from (
83- a. iter ( )
84- . cloned ( )
85- . chain ( b. iter ( ) . map ( |it| {
86- let mut it = it. clone ( ) ;
87- it. id . id = it. id . ast_index ( ) as u32 + last_ast_index
88- | ( it. id . cfg_attr_index ( ) . unwrap_or ( 0 ) as u32 )
89- << AttrId :: AST_INDEX_BITS ;
90- it
91- } ) )
92- // FIXME: use `Arc::from_iter` when it becomes available
93- . collect :: < Vec < _ > > ( ) ,
94- ) ) ,
79+ entries : Some ( Arc :: from_iter ( a. iter ( ) . cloned ( ) . chain ( b. iter ( ) . map ( |it| {
80+ let mut it = it. clone ( ) ;
81+ it. id . id = it. id . ast_index ( ) as u32 + last_ast_index
82+ | ( it. id . cfg_attr_index ( ) . unwrap_or ( 0 ) as u32 )
83+ << AttrId :: AST_INDEX_BITS ;
84+ it
85+ } ) ) ) ) ,
9586 }
9687 }
9788 }
@@ -108,49 +99,43 @@ impl RawAttrs {
10899 }
109100
110101 let crate_graph = db. crate_graph ( ) ;
111- let new_attrs = Arc :: from (
112- self . iter ( )
113- . flat_map ( |attr| -> SmallVec < [ _ ; 1 ] > {
114- let is_cfg_attr =
115- attr. path . as_ident ( ) . map_or ( false , |name| * name == crate :: name![ cfg_attr] ) ;
116- if !is_cfg_attr {
117- return smallvec ! [ attr. clone( ) ] ;
118- }
119-
120- let subtree = match attr. token_tree_value ( ) {
121- Some ( it) => it,
122- _ => return smallvec ! [ attr. clone( ) ] ,
123- } ;
102+ let new_attrs = Arc :: from_iter ( self . iter ( ) . flat_map ( |attr| -> SmallVec < [ _ ; 1 ] > {
103+ let is_cfg_attr =
104+ attr. path . as_ident ( ) . map_or ( false , |name| * name == crate :: name![ cfg_attr] ) ;
105+ if !is_cfg_attr {
106+ return smallvec ! [ attr. clone( ) ] ;
107+ }
124108
125- let ( cfg, parts) = match parse_cfg_attr_input ( subtree) {
126- Some ( it) => it,
127- None => return smallvec ! [ attr. clone( ) ] ,
109+ let subtree = match attr. token_tree_value ( ) {
110+ Some ( it) => it,
111+ _ => return smallvec ! [ attr. clone( ) ] ,
112+ } ;
113+
114+ let ( cfg, parts) = match parse_cfg_attr_input ( subtree) {
115+ Some ( it) => it,
116+ None => return smallvec ! [ attr. clone( ) ] ,
117+ } ;
118+ let index = attr. id ;
119+ let attrs =
120+ parts. enumerate ( ) . take ( 1 << AttrId :: CFG_ATTR_BITS ) . filter_map ( |( idx, attr) | {
121+ let tree = Subtree {
122+ delimiter : tt:: Delimiter :: dummy_invisible ( ) ,
123+ token_trees : attr. to_vec ( ) ,
128124 } ;
129- let index = attr. id ;
130- let attrs = parts. enumerate ( ) . take ( 1 << AttrId :: CFG_ATTR_BITS ) . filter_map (
131- |( idx, attr) | {
132- let tree = Subtree {
133- delimiter : tt:: Delimiter :: dummy_invisible ( ) ,
134- token_trees : attr. to_vec ( ) ,
135- } ;
136- Attr :: from_tt ( db, & tree, index. with_cfg_attr ( idx) )
137- } ,
138- ) ;
139-
140- let cfg_options = & crate_graph[ krate] . cfg_options ;
141- let cfg = Subtree { delimiter : subtree. delimiter , token_trees : cfg. to_vec ( ) } ;
142- let cfg = CfgExpr :: parse ( & cfg) ;
143- if cfg_options. check ( & cfg) == Some ( false ) {
144- smallvec ! [ ]
145- } else {
146- cov_mark:: hit!( cfg_attr_active) ;
147-
148- attrs. collect ( )
149- }
150- } )
151- // FIXME: use `Arc::from_iter` when it becomes available
152- . collect :: < Vec < _ > > ( ) ,
153- ) ;
125+ Attr :: from_tt ( db, & tree, index. with_cfg_attr ( idx) )
126+ } ) ;
127+
128+ let cfg_options = & crate_graph[ krate] . cfg_options ;
129+ let cfg = Subtree { delimiter : subtree. delimiter , token_trees : cfg. to_vec ( ) } ;
130+ let cfg = CfgExpr :: parse ( & cfg) ;
131+ if cfg_options. check ( & cfg) == Some ( false ) {
132+ smallvec ! [ ]
133+ } else {
134+ cov_mark:: hit!( cfg_attr_active) ;
135+
136+ attrs. collect ( )
137+ }
138+ } ) ) ;
154139
155140 RawAttrs { entries : Some ( new_attrs) }
156141 }
0 commit comments