@@ -194,7 +194,7 @@ use rustc_hir as hir;
194194use rustc_hir:: def_id:: { DefId , DefIdMap , LOCAL_CRATE } ;
195195use rustc_hir:: itemlikevisit:: ItemLikeVisitor ;
196196use rustc_index:: bit_set:: GrowableBitSet ;
197-
197+ use smallvec :: SmallVec ;
198198use std:: iter;
199199
200200#[ derive( PartialEq ) ]
@@ -227,28 +227,23 @@ impl<'tcx> InliningMap<'tcx> {
227227 }
228228 }
229229
230- fn record_accesses < I > ( & mut self , source : MonoItem < ' tcx > , new_targets : I )
231- where
232- I : Iterator < Item = ( MonoItem < ' tcx > , bool ) > + ExactSizeIterator ,
233- {
234- assert ! ( !self . index. contains_key( & source) ) ;
235-
230+ fn record_accesses ( & mut self , source : MonoItem < ' tcx > , new_targets : & [ ( MonoItem < ' tcx > , bool ) ] ) {
236231 let start_index = self . targets . len ( ) ;
237232 let new_items_count = new_targets. len ( ) ;
238233 let new_items_count_total = new_items_count + self . targets . len ( ) ;
239234
240235 self . targets . reserve ( new_items_count) ;
241236 self . inlines . ensure ( new_items_count_total) ;
242237
243- for ( i, ( target, inline) ) in new_targets. enumerate ( ) {
244- self . targets . push ( target) ;
245- if inline {
238+ for ( i, ( target, inline) ) in new_targets. iter ( ) . enumerate ( ) {
239+ self . targets . push ( * target) ;
240+ if * inline {
246241 self . inlines . insert ( i + start_index) ;
247242 }
248243 }
249244
250245 let end_index = self . targets . len ( ) ;
251- self . index . insert ( source, ( start_index, end_index) ) ;
246+ assert ! ( self . index. insert( source, ( start_index, end_index) ) . is_none ( ) ) ;
252247 }
253248
254249 // Internally iterate over all items referenced by `source` which will be
@@ -403,10 +398,15 @@ fn record_accesses<'tcx>(
403398 mono_item. instantiation_mode ( tcx) == InstantiationMode :: LocalCopy
404399 } ;
405400
406- let accesses =
407- callees. into_iter ( ) . map ( |mono_item| ( * mono_item, is_inlining_candidate ( mono_item) ) ) ;
401+ // We collect this into a `SmallVec` to avoid calling `is_inlining_candidate` in the lock.
402+ // FIXME: Call `is_inlining_candidate` when pushing to `neighbors` in `collect_items_rec`
403+ // instead to avoid creating this `SmallVec`.
404+ let accesses: SmallVec < [ _ ; 128 ] > = callees
405+ . into_iter ( )
406+ . map ( |mono_item| ( * mono_item, is_inlining_candidate ( mono_item) ) )
407+ . collect ( ) ;
408408
409- inlining_map. lock_mut ( ) . record_accesses ( caller, accesses) ;
409+ inlining_map. lock_mut ( ) . record_accesses ( caller, & accesses) ;
410410}
411411
412412fn check_recursion_limit < ' tcx > (
0 commit comments