Skip to content

Commit

Permalink
Avoid cloning Place in check_and_patch
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Jul 20, 2019
1 parent b59ded8 commit a8ceeeb
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/librustc_mir/transform/uniform_array_move_out.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,10 @@ impl MirPass for RestoreSubsliceArrayMoveOut {
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 {
Expand All @@ -237,17 +238,17 @@ impl RestoreSubsliceArrayMoveOut {
// indices is an integer interval. If all checks pass do the replacent.
// items are Vec<Option<LocalUse, index in source array, source place for init local>>
fn check_and_patch<'tcx>(candidate: Location,
items: &[Option<(&LocalUse, u32, Place<'tcx>)>],
items: &[Option<(&LocalUse, u32, PlaceRef<'_, 'tcx>)>],
opt_size: Option<u64>,
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;
Expand All @@ -258,7 +259,7 @@ impl RestoreSubsliceArrayMoveOut {
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());
Expand All @@ -279,7 +280,7 @@ impl RestoreSubsliceArrayMoveOut {
}

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 {
Expand All @@ -298,9 +299,9 @@ impl RestoreSubsliceArrayMoveOut {
}
}),
}))) = &statement.kind {
return Some((*offset, Place {
base: base.clone(),
projection: proj_base.clone(),
return Some((*offset, PlaceRef {
base,
projection: proj_base,
}))
}
}
Expand Down

0 comments on commit a8ceeeb

Please sign in to comment.