diff options
| author | Lzu Tao <taolzu@gmail.com> | 2024-06-16 10:00:23 +0000 |
|---|---|---|
| committer | Lzu Tao <taolzu@gmail.com> | 2024-06-21 13:51:33 +0000 |
| commit | 62a287528a55bfc96e4e97d7889af68fb9bb8307 (patch) | |
| tree | c8be390b85a20b20b71da4bddfa87dca0e261190 | |
| parent | c03659443a70b018e49f2ae72645d64eac58c7f7 (diff) | |
| download | rust-62a287528a55bfc96e4e97d7889af68fb9bb8307.tar.gz rust-62a287528a55bfc96e4e97d7889af68fb9bb8307.zip | |
Reuse allocation for Vec<Candidate>
| -rw-r--r-- | compiler/rustc_mir_transform/src/promote_consts.rs | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/compiler/rustc_mir_transform/src/promote_consts.rs b/compiler/rustc_mir_transform/src/promote_consts.rs index 2f7d8d96eac..ba7c5f2fee6 100644 --- a/compiler/rustc_mir_transform/src/promote_consts.rs +++ b/compiler/rustc_mir_transform/src/promote_consts.rs @@ -60,7 +60,7 @@ impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> { let ccx = ConstCx::new(tcx, body); let (mut temps, all_candidates) = collect_temps_and_candidates(&ccx); - let promotable_candidates = validate_candidates(&ccx, &mut temps, &all_candidates); + let promotable_candidates = validate_candidates(&ccx, &mut temps, all_candidates); let promoted = promote_candidates(body, tcx, temps, promotable_candidates); self.promoted_fragments.set(promoted); @@ -691,15 +691,12 @@ impl<'tcx> Validator<'_, 'tcx> { fn validate_candidates( ccx: &ConstCx<'_, '_>, temps: &mut IndexSlice<Local, TempState>, - candidates: &[Candidate], + mut candidates: Vec<Candidate>, ) -> Vec<Candidate> { let mut validator = Validator { ccx, temps, promotion_safe_blocks: None }; + candidates.retain(|&candidate| validator.validate_candidate(candidate).is_ok()); candidates - .iter() - .copied() - .filter(|&candidate| validator.validate_candidate(candidate).is_ok()) - .collect() } struct Promoter<'a, 'tcx> { |
