@@ -194,7 +194,7 @@ use rustc_hir as hir;
194
194
use rustc_hir:: def_id:: { DefId , DefIdMap , LOCAL_CRATE } ;
195
195
use rustc_hir:: itemlikevisit:: ItemLikeVisitor ;
196
196
use rustc_index:: bit_set:: GrowableBitSet ;
197
-
197
+ use smallvec :: SmallVec ;
198
198
use std:: iter;
199
199
200
200
#[ derive( PartialEq ) ]
@@ -227,28 +227,23 @@ impl<'tcx> InliningMap<'tcx> {
227
227
}
228
228
}
229
229
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 ) ] ) {
236
231
let start_index = self . targets . len ( ) ;
237
232
let new_items_count = new_targets. len ( ) ;
238
233
let new_items_count_total = new_items_count + self . targets . len ( ) ;
239
234
240
235
self . targets . reserve ( new_items_count) ;
241
236
self . inlines . ensure ( new_items_count_total) ;
242
237
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 {
246
241
self . inlines . insert ( i + start_index) ;
247
242
}
248
243
}
249
244
250
245
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 ( ) ) ;
252
247
}
253
248
254
249
// Internally iterate over all items referenced by `source` which will be
@@ -403,10 +398,15 @@ fn record_accesses<'tcx>(
403
398
mono_item. instantiation_mode ( tcx) == InstantiationMode :: LocalCopy
404
399
} ;
405
400
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 ( ) ;
408
408
409
- inlining_map. lock_mut ( ) . record_accesses ( caller, accesses) ;
409
+ inlining_map. lock_mut ( ) . record_accesses ( caller, & accesses) ;
410
410
}
411
411
412
412
fn check_recursion_limit < ' tcx > (
0 commit comments