Skip to content

Commit fe3b646

Browse files
committed
Merge the two loops in internalize_symbols.
Because they have a lot of overlap.
1 parent 392045b commit fe3b646

File tree

1 file changed

+19
-30
lines changed

1 file changed

+19
-30
lines changed

compiler/rustc_monomorphize/src/partitioning.rs

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -486,21 +486,7 @@ fn internalize_symbols<'tcx>(
486486
mono_item_placements: FxHashMap<MonoItem<'tcx>, MonoItemPlacement>,
487487
internalization_candidates: FxHashSet<MonoItem<'tcx>>,
488488
) {
489-
if codegen_units.len() == 1 {
490-
// Fast path for when there is only one codegen unit. In this case we
491-
// can internalize all candidates, since there is nowhere else they
492-
// could be used from.
493-
for cgu in codegen_units {
494-
for (item, linkage_and_visibility) in cgu.items_mut() {
495-
if !internalization_candidates.contains(item) {
496-
// This item is no candidate for internalizing, so skip it.
497-
continue;
498-
}
499-
*linkage_and_visibility = (Linkage::Internal, Visibility::Default);
500-
}
501-
}
502-
return;
503-
}
489+
let single_codegen_unit = codegen_units.len() == 1;
504490

505491
// For each internalization candidates in each codegen unit, check if it is
506492
// used from outside its defining codegen unit.
@@ -512,21 +498,24 @@ fn internalize_symbols<'tcx>(
512498
// This item is no candidate for internalizing, so skip it.
513499
continue;
514500
}
515-
debug_assert_eq!(mono_item_placements[item], home_cgu);
516-
517-
if let Some(user_items) = cx.usage_map.get_user_items(*item) {
518-
if user_items
519-
.iter()
520-
.filter_map(|user_item| {
521-
// Some user mono items might not have been
522-
// instantiated. We can safely ignore those.
523-
mono_item_placements.get(user_item)
524-
})
525-
.any(|placement| *placement != home_cgu)
526-
{
527-
// Found a user from another CGU, so skip to the next item
528-
// without marking this one as internal.
529-
continue;
501+
502+
if !single_codegen_unit {
503+
debug_assert_eq!(mono_item_placements[item], home_cgu);
504+
505+
if let Some(user_items) = cx.usage_map.get_user_items(*item) {
506+
if user_items
507+
.iter()
508+
.filter_map(|user_item| {
509+
// Some user mono items might not have been
510+
// instantiated. We can safely ignore those.
511+
mono_item_placements.get(user_item)
512+
})
513+
.any(|placement| *placement != home_cgu)
514+
{
515+
// Found a user from another CGU, so skip to the next item
516+
// without marking this one as internal.
517+
continue;
518+
}
530519
}
531520
}
532521

0 commit comments

Comments
 (0)