Skip to content

Commit

Permalink
Optimize clone shim for Copy types
Browse files Browse the repository at this point in the history
  • Loading branch information
scalexm committed Aug 14, 2017
1 parent 4e4e55a commit df7be43
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/librustc_mir/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,20 @@ fn build_clone_shim<'a, 'tcx>(tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
loc
};

let is_copy = !self_ty.moves_by_default(tcx, tcx.param_env(def_id), span);

match self_ty.sty {
_ if is_copy => {
// `return *self;`
let statement = Statement {
source_info: source_info,
kind: StatementKind::Assign(
Lvalue::Local(RETURN_POINTER),
Rvalue::Use(Operand::Consume(rcvr))
)
};
block(&mut blocks, statement, TerminatorKind::Return);
}
ty::TyArray(ty, len) => {
let mut returns = Vec::new();
for i in 0..len {
Expand Down Expand Up @@ -402,15 +415,7 @@ fn build_clone_shim<'a, 'tcx>(tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
block(&mut blocks, statement, TerminatorKind::Return);
}
_ => {
// `return *self;`
let statement = Statement {
source_info: source_info,
kind: StatementKind::Assign(
Lvalue::Local(RETURN_POINTER),
Rvalue::Use(Operand::Consume(rcvr))
)
};
block(&mut blocks, statement, TerminatorKind::Return);
bug!("builtin shim for `{:?}` which is not `Copy` and is not an aggregate", self_ty);
}
};

Expand Down

0 comments on commit df7be43

Please sign in to comment.