Skip to content

Commit 0ee0889

Browse files
committed
interpret: avoid some clone() in argument handling
1 parent 7d63e43 commit 0ee0889

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

compiler/rustc_const_eval/src/interpret/terminator.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ impl<'tcx, Prov: Provenance> FnArg<'tcx, Prov> {
4040
impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
4141
/// Make a copy of the given fn_arg. Any `InPlace` are degenerated to copies, no protection of the
4242
/// original memory occurs.
43-
pub fn copy_fn_arg(
43+
pub fn copy_fn_arg<'a>(
4444
&self,
45-
arg: &FnArg<'tcx, M::Provenance>,
46-
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
45+
arg: &'a FnArg<'tcx, M::Provenance>,
46+
) -> InterpResult<'tcx, Cow<'a, OpTy<'tcx, M::Provenance>>> {
4747
match arg {
48-
FnArg::Copy(op) => Ok(op.clone()),
49-
FnArg::InPlace(place) => self.place_to_op(&place),
48+
FnArg::Copy(op) => Ok(Cow::Borrowed(op)),
49+
FnArg::InPlace(place) => Ok(Cow::Owned(self.place_to_op(&place)?)),
5050
}
5151
}
5252

@@ -56,7 +56,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
5656
&self,
5757
args: &[FnArg<'tcx, M::Provenance>],
5858
) -> InterpResult<'tcx, Vec<OpTy<'tcx, M::Provenance>>> {
59-
args.iter().map(|fn_arg| self.copy_fn_arg(fn_arg)).collect()
59+
args.iter().map(|fn_arg| self.copy_fn_arg(fn_arg).map(|x| x.into_owned())).collect()
6060
}
6161

6262
pub fn fn_arg_field(
@@ -637,7 +637,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
637637
// An `InPlace` does nothing here, we keep the original receiver intact. We can't
638638
// really pass the argument in-place anyway, and we are constructing a new
639639
// `Immediate` receiver.
640-
let mut receiver = self.copy_fn_arg(&args[0])?;
640+
let mut receiver = self.copy_fn_arg(&args[0])?.into_owned();
641641
let receiver_place = loop {
642642
match receiver.layout.ty.kind() {
643643
ty::Ref(..) | ty::RawPtr(..) => {

0 commit comments

Comments
 (0)