Skip to content

Commit 7e786e8

Browse files
committed
Avoid cloning LocalDecls.
`DerefChecker` can just hold a reference instead. This avoids quite a lot of allocations for some benchmarks.
1 parent 8d7084d commit 7e786e8

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

compiler/rustc_mir_transform/src/deref_separator.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ use rustc_middle::ty::TyCtxt;
88

99
pub struct Derefer;
1010

11-
pub struct DerefChecker<'tcx> {
11+
pub struct DerefChecker<'a, 'tcx> {
1212
tcx: TyCtxt<'tcx>,
1313
patcher: MirPatch<'tcx>,
14-
local_decls: IndexVec<Local, LocalDecl<'tcx>>,
14+
local_decls: &'a IndexVec<Local, LocalDecl<'tcx>>,
1515
}
1616

17-
impl<'tcx> MutVisitor<'tcx> for DerefChecker<'tcx> {
17+
impl<'a, 'tcx> MutVisitor<'tcx> for DerefChecker<'a, 'tcx> {
1818
fn tcx(&self) -> TyCtxt<'tcx> {
1919
self.tcx
2020
}
@@ -36,7 +36,7 @@ impl<'tcx> MutVisitor<'tcx> for DerefChecker<'tcx> {
3636

3737
for (idx, (p_ref, p_elem)) in place.iter_projections().enumerate() {
3838
if !p_ref.projection.is_empty() && p_elem == ProjectionElem::Deref {
39-
let ty = p_ref.ty(&self.local_decls, self.tcx).ty;
39+
let ty = p_ref.ty(self.local_decls, self.tcx).ty;
4040
let temp = self.patcher.new_internal_with_info(
4141
ty,
4242
self.local_decls[p_ref.local].source_info.span,
@@ -70,7 +70,7 @@ impl<'tcx> MutVisitor<'tcx> for DerefChecker<'tcx> {
7070

7171
pub fn deref_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
7272
let patch = MirPatch::new(body);
73-
let mut checker = DerefChecker { tcx, patcher: patch, local_decls: body.local_decls.clone() };
73+
let mut checker = DerefChecker { tcx, patcher: patch, local_decls: &body.local_decls };
7474

7575
for (bb, data) in body.basic_blocks.as_mut_preserves_cfg().iter_enumerated_mut() {
7676
checker.visit_basic_block_data(bb, data);

0 commit comments

Comments
 (0)