Use move semantics when returning a local var

(Since the variable won't be used after return anyway.)
This commit is contained in:
Marijn Haverbeke 2011-08-19 10:06:20 +02:00
parent f6ae60a432
commit bc998c6140

View File

@ -5369,8 +5369,20 @@ fn trans_ret(cx: &@block_ctxt, e: &option::t<@ast::expr>) -> result {
let t = ty::expr_ty(bcx_tcx(cx), x);
let lv = trans_lval(cx, x);
bcx = lv.res.bcx;
let is_local = alt x.node {
ast::expr_path(p) {
alt bcx_tcx(bcx).def_map.get(x.id) {
ast::def_local(_) { true } _ { false }
}
}
_ { false }
};
if is_local {
bcx = move_val(bcx, INIT, cx.fcx.llretptr, lv, t).bcx;
} else {
bcx = move_val_if_temp(bcx, INIT, cx.fcx.llretptr, lv, t).bcx;
}
}
_ {
let t = llvm::LLVMGetElementType(val_ty(cx.fcx.llretptr));
bcx.build.Store(C_null(t), cx.fcx.llretptr);