Skip to content

Commit 3af5f38

Browse files
eddybalexcrichton
authored andcommitted
Don't copy &Trait and &mut Trait to temporaries for every call.
1 parent ee2a888 commit 3af5f38

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/librustc/middle/trans/meth.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -353,17 +353,24 @@ fn trans_trait_callee<'a>(bcx: &'a Block<'a>,
353353
// converting to an rvalue.
354354
let self_datum = unpack_datum!(
355355
bcx, expr::trans(bcx, self_expr));
356-
let self_datum = unpack_datum!(
357-
bcx, self_datum.to_rvalue_datum(bcx, "trait_callee"));
358356

359-
// Convert to by-ref since `trans_trait_callee_from_llval` wants it
360-
// that way.
361-
let self_datum = unpack_datum!(
362-
bcx, self_datum.to_ref_datum(bcx));
357+
let llval = if ty::type_needs_drop(bcx.tcx(), self_datum.ty) {
358+
let self_datum = unpack_datum!(
359+
bcx, self_datum.to_rvalue_datum(bcx, "trait_callee"));
360+
361+
// Convert to by-ref since `trans_trait_callee_from_llval` wants it
362+
// that way.
363+
let self_datum = unpack_datum!(
364+
bcx, self_datum.to_ref_datum(bcx));
363365

364-
// Arrange cleanup in case something should go wrong before the
365-
// actual call occurs.
366-
let llval = self_datum.add_clean(bcx.fcx, arg_cleanup_scope);
366+
// Arrange cleanup in case something should go wrong before the
367+
// actual call occurs.
368+
self_datum.add_clean(bcx.fcx, arg_cleanup_scope)
369+
} else {
370+
// We don't have to do anything about cleanups for &Trait and &mut Trait.
371+
assert!(self_datum.kind.is_by_ref());
372+
self_datum.val
373+
};
367374

368375
let callee_ty = node_id_type(bcx, callee_id);
369376
trans_trait_callee_from_llval(bcx, callee_ty, n_method, llval)

0 commit comments

Comments
 (0)