From a8ceeeb5a0f4a5d274ef7a0f434c5d16e09f864b Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sat, 20 Jul 2019 03:40:33 +0200 Subject: [PATCH] Avoid cloning Place in check_and_patch --- .../transform/uniform_array_move_out.rs | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/librustc_mir/transform/uniform_array_move_out.rs b/src/librustc_mir/transform/uniform_array_move_out.rs index 887601338ff..6aceeebaea1 100644 --- a/src/librustc_mir/transform/uniform_array_move_out.rs +++ b/src/librustc_mir/transform/uniform_array_move_out.rs @@ -214,9 +214,10 @@ fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx>, _src: MirSource<'tcx>, body: &mut Bo None }).collect(); - let opt_src_place = items.first().and_then(|x| x.clone()).map(|x| x.2); + let opt_src_place = items.first().and_then(|x| *x).map(|x| x.2); let opt_size = opt_src_place.and_then(|src_place| { - let src_ty = src_place.ty(body, tcx).ty; + let src_ty = + Place::ty_from(src_place.base, src_place.projection, body, tcx).ty; if let ty::Array(_, ref size_o) = src_ty.sty { size_o.assert_usize(tcx) } else { @@ -237,17 +238,17 @@ impl RestoreSubsliceArrayMoveOut { // indices is an integer interval. If all checks pass do the replacent. // items are Vec> fn check_and_patch<'tcx>(candidate: Location, - items: &[Option<(&LocalUse, u32, Place<'tcx>)>], + items: &[Option<(&LocalUse, u32, PlaceRef<'_, 'tcx>)>], opt_size: Option, patch: &mut MirPatch<'tcx>, dst_place: &Place<'tcx>) { - let opt_src_place = items.first().and_then(|x| x.clone()).map(|x| x.2); + let opt_src_place = items.first().and_then(|x| *x).map(|x| x.2); if opt_size.is_some() && items.iter().all( - |l| l.is_some() && l.clone().unwrap().2 == opt_src_place.clone().unwrap()) { - let src_place = opt_src_place.clone().unwrap(); + |l| l.is_some() && l.unwrap().2 == opt_src_place.unwrap()) { + let src_place = opt_src_place.unwrap(); - let indices: Vec<_> = items.iter().map(|x| x.clone().unwrap().1).collect(); + let indices: Vec<_> = items.iter().map(|x| x.unwrap().1).collect(); for i in 1..indices.len() { if indices[i - 1] + 1 != indices[i] { return; @@ -258,7 +259,7 @@ fn check_and_patch<'tcx>(candidate: Location, let max = *indices.last().unwrap(); for item in items { - let locals_use = item.clone().unwrap().0; + let locals_use = item.unwrap().0; patch.make_nop(locals_use.alive.unwrap()); patch.make_nop(locals_use.dead.unwrap()); patch.make_nop(locals_use.first_use.unwrap()); @@ -279,7 +280,7 @@ fn check_and_patch<'tcx>(candidate: Location, } fn try_get_item_source<'a, 'tcx>(local_use: &LocalUse, - body: &'a Body<'tcx>) -> Option<(u32, Place<'tcx>)> { + body: &'a Body<'tcx>) -> Option<(u32, PlaceRef<'a, 'tcx>)> { if let Some(location) = local_use.first_use { let block = &body[location.block]; if block.statements.len() > location.statement_index { @@ -298,9 +299,9 @@ fn try_get_item_source<'a, 'tcx>(local_use: &LocalUse, } }), }))) = &statement.kind { - return Some((*offset, Place { - base: base.clone(), - projection: proj_base.clone(), + return Some((*offset, PlaceRef { + base, + projection: proj_base, })) } } -- 2.44.0