@@ -146,25 +146,30 @@ impl<'hir> Iterator for ParentOwnerIterator<'hir> {
146
146
}
147
147
148
148
impl < ' hir > Map < ' hir > {
149
+ #[ inline]
149
150
pub fn krate ( self ) -> & ' hir Crate < ' hir > {
150
151
self . tcx . hir_crate ( ( ) )
151
152
}
152
153
154
+ #[ inline]
153
155
pub fn root_module ( self ) -> & ' hir Mod < ' hir > {
154
156
match self . tcx . hir_owner ( CRATE_DEF_ID ) . map ( |o| o. node ) {
155
157
Some ( OwnerNode :: Crate ( item) ) => item,
156
158
_ => bug ! ( ) ,
157
159
}
158
160
}
159
161
162
+ #[ inline]
160
163
pub fn items ( self ) -> impl Iterator < Item = ItemId > + ' hir {
161
164
self . tcx . hir_crate_items ( ( ) ) . items . iter ( ) . copied ( )
162
165
}
163
166
167
+ #[ inline]
164
168
pub fn module_items ( self , module : LocalDefId ) -> impl Iterator < Item = ItemId > + ' hir {
165
169
self . tcx . hir_module_items ( module) . items ( )
166
170
}
167
171
172
+ #[ inline]
168
173
pub fn par_for_each_item ( self , f : impl Fn ( ItemId ) + Sync + Send ) {
169
174
par_for_each_in ( & self . tcx . hir_crate_items ( ( ) ) . items [ ..] , |id| f ( * id) ) ;
170
175
}
@@ -489,11 +494,13 @@ impl<'hir> Map<'hir> {
489
494
/// Returns an iterator of the `DefId`s for all body-owners in this
490
495
/// crate. If you would prefer to iterate over the bodies
491
496
/// themselves, you can do `self.hir().krate().body_ids.iter()`.
497
+ #[ inline]
492
498
pub fn body_owners ( self ) -> impl Iterator < Item = LocalDefId > + ' hir {
493
499
self . tcx . hir_crate_items ( ( ) ) . body_owners . iter ( ) . copied ( )
494
500
}
495
501
496
- pub fn par_body_owners < F : Fn ( LocalDefId ) + Sync + Send > ( self , f : F ) {
502
+ #[ inline]
503
+ pub fn par_body_owners ( self , f : impl Fn ( LocalDefId ) + Sync + Send ) {
497
504
par_for_each_in ( & self . tcx . hir_crate_items ( ( ) ) . body_owners [ ..] , |& def_id| f ( def_id) ) ;
498
505
}
499
506
@@ -626,35 +633,22 @@ impl<'hir> Map<'hir> {
626
633
}
627
634
}
628
635
629
- #[ cfg( not( parallel_compiler) ) ]
630
636
#[ inline]
631
- pub fn par_for_each_module ( self , f : impl Fn ( LocalDefId ) ) {
632
- self . for_each_module ( f)
633
- }
634
-
635
- #[ cfg( parallel_compiler) ]
636
- pub fn par_for_each_module ( self , f : impl Fn ( LocalDefId ) + Sync ) {
637
- use rustc_data_structures:: sync:: { par_iter, ParallelIterator } ;
638
- par_iter_submodules ( self . tcx , CRATE_DEF_ID , & f) ;
639
-
640
- fn par_iter_submodules < F > ( tcx : TyCtxt < ' _ > , module : LocalDefId , f : & F )
641
- where
642
- F : Fn ( LocalDefId ) + Sync ,
643
- {
644
- ( * f) ( module) ;
645
- let items = tcx. hir_module_items ( module) ;
646
- par_iter ( & items. submodules [ ..] ) . for_each ( |& sm| par_iter_submodules ( tcx, sm, f) ) ;
647
- }
637
+ pub fn par_for_each_module ( self , f : impl Fn ( LocalDefId ) + Sync + Send ) {
638
+ let crate_items = self . tcx . hir_crate_items ( ( ) ) ;
639
+ par_for_each_in ( & crate_items. submodules [ ..] , |module| f ( * module) )
648
640
}
649
641
650
642
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
651
643
/// until the crate root is reached. Prefer this over your own loop using `get_parent_node`.
644
+ #[ inline]
652
645
pub fn parent_iter ( self , current_id : HirId ) -> ParentHirIterator < ' hir > {
653
646
ParentHirIterator { current_id, map : self }
654
647
}
655
648
656
649
/// Returns an iterator for the nodes in the ancestor tree of the `current_id`
657
650
/// until the crate root is reached. Prefer this over your own loop using `get_parent_node`.
651
+ #[ inline]
658
652
pub fn parent_owner_iter ( self , current_id : HirId ) -> ParentOwnerIterator < ' hir > {
659
653
ParentOwnerIterator { current_id, map : self }
660
654
}
0 commit comments