Skip to content

Commit 62a2875

Browse files
committed
Reuse allocation for Vec<Candidate>
1 parent c036594 commit 62a2875

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

compiler/rustc_mir_transform/src/promote_consts.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> {
6060
let ccx = ConstCx::new(tcx, body);
6161
let (mut temps, all_candidates) = collect_temps_and_candidates(&ccx);
6262

63-
let promotable_candidates = validate_candidates(&ccx, &mut temps, &all_candidates);
63+
let promotable_candidates = validate_candidates(&ccx, &mut temps, all_candidates);
6464

6565
let promoted = promote_candidates(body, tcx, temps, promotable_candidates);
6666
self.promoted_fragments.set(promoted);
@@ -691,15 +691,12 @@ impl<'tcx> Validator<'_, 'tcx> {
691691
fn validate_candidates(
692692
ccx: &ConstCx<'_, '_>,
693693
temps: &mut IndexSlice<Local, TempState>,
694-
candidates: &[Candidate],
694+
mut candidates: Vec<Candidate>,
695695
) -> Vec<Candidate> {
696696
let mut validator = Validator { ccx, temps, promotion_safe_blocks: None };
697697

698+
candidates.retain(|&candidate| validator.validate_candidate(candidate).is_ok());
698699
candidates
699-
.iter()
700-
.copied()
701-
.filter(|&candidate| validator.validate_candidate(candidate).is_ok())
702-
.collect()
703700
}
704701

705702
struct Promoter<'a, 'tcx> {

0 commit comments

Comments
 (0)