Skip to content

Commit

Permalink
Don't copy &Trait and &mut Trait to temporaries for every call.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb authored and alexcrichton committed Feb 14, 2014
1 parent ee2a888 commit 3af5f38
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/librustc/middle/trans/meth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,17 +353,24 @@ fn trans_trait_callee<'a>(bcx: &'a Block<'a>,
// converting to an rvalue.
let self_datum = unpack_datum!(
bcx, expr::trans(bcx, self_expr));
let self_datum = unpack_datum!(
bcx, self_datum.to_rvalue_datum(bcx, "trait_callee"));

// Convert to by-ref since `trans_trait_callee_from_llval` wants it
// that way.
let self_datum = unpack_datum!(
bcx, self_datum.to_ref_datum(bcx));
let llval = if ty::type_needs_drop(bcx.tcx(), self_datum.ty) {
let self_datum = unpack_datum!(
bcx, self_datum.to_rvalue_datum(bcx, "trait_callee"));

// Convert to by-ref since `trans_trait_callee_from_llval` wants it
// that way.
let self_datum = unpack_datum!(
bcx, self_datum.to_ref_datum(bcx));

// Arrange cleanup in case something should go wrong before the
// actual call occurs.
let llval = self_datum.add_clean(bcx.fcx, arg_cleanup_scope);
// Arrange cleanup in case something should go wrong before the
// actual call occurs.
self_datum.add_clean(bcx.fcx, arg_cleanup_scope)
} else {
// We don't have to do anything about cleanups for &Trait and &mut Trait.
assert!(self_datum.kind.is_by_ref());
self_datum.val
};

let callee_ty = node_id_type(bcx, callee_id);
trans_trait_callee_from_llval(bcx, callee_ty, n_method, llval)
Expand Down

0 comments on commit 3af5f38

Please sign in to comment.