about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBjörn Steinbrink <bsteinbr@gmail.com>2014-06-22 15:32:55 +0200
committerAlex Crichton <alex@alexcrichton.com>2014-06-24 17:23:19 -0700
commita0ec902e239b2219edf1a18b036dd32c18d3be42 (patch)
tree63611b35f8f2f40c3f5263429ffbdbc41fdc5273
parente4e3550ff6ee1754ea4d7191989044c444bff049 (diff)
Avoid unnecessary temporary on assignments
We only need the temporary when the type needs to be dropped, for other
types, we can use trans_into to directly place the value into the
destination.
-rw-r--r--src/librustc/middle/trans/expr.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs
index 9af5c7aa792..2a01e165f3c 100644
--- a/src/librustc/middle/trans/expr.rs
+++ b/src/librustc/middle/trans/expr.rs
@@ -610,7 +610,6 @@ fn trans_rvalue_stmt_unadjusted<'a>(bcx: &'a Block<'a>,
             controlflow::trans_loop(bcx, expr.id, &**body)
         }
         ast::ExprAssign(ref dst, ref src) => {
-            let src_datum = unpack_datum!(bcx, trans(bcx, &**src));
             let dst_datum = unpack_datum!(bcx, trans_to_lvalue(bcx, &**dst, "assign"));
 
             if ty::type_needs_drop(bcx.tcx(), dst_datum.ty) {
@@ -630,12 +629,13 @@ fn trans_rvalue_stmt_unadjusted<'a>(bcx: &'a Block<'a>,
                 //
                 // We could avoid this intermediary with some analysis
                 // to determine whether `dst` may possibly own `src`.
+                let src_datum = unpack_datum!(bcx, trans(bcx, &**src));
                 let src_datum = unpack_datum!(
                     bcx, src_datum.to_rvalue_datum(bcx, "ExprAssign"));
                 bcx = glue::drop_ty(bcx, dst_datum.val, dst_datum.ty);
                 src_datum.store_to(bcx, dst_datum.val)
             } else {
-                src_datum.store_to(bcx, dst_datum.val)
+                trans_into(bcx, &**src, SaveIn(dst_datum.to_llref()))
             }
         }
         ast::ExprAssignOp(op, ref dst, ref src) => {