Simplify copying of uniques

We can call take glue, rather than duplicating it inline.
This commit is contained in:
Marijn Haverbeke 2011-10-12 10:14:21 +02:00
parent 75bda422df
commit 306f7fb25f
2 changed files with 3 additions and 27 deletions

View file

@ -2092,22 +2092,12 @@ fn copy_val_no_check(bcx: @block_ctxt, action: copy_action, dst: ValueRef,
ret bcx; ret bcx;
} }
if ty::type_is_nil(ccx.tcx, t) || ty::type_is_bot(ccx.tcx, t) { ret bcx; } if ty::type_is_nil(ccx.tcx, t) || ty::type_is_bot(ccx.tcx, t) { ret bcx; }
if ty::type_is_boxed(ccx.tcx, t) { if ty::type_is_boxed(ccx.tcx, t) || ty::type_is_vec(ccx.tcx, t) ||
ty::type_is_unique_box(ccx.tcx, t) {
if action == DROP_EXISTING { bcx = drop_ty(bcx, dst, t); } if action == DROP_EXISTING { bcx = drop_ty(bcx, dst, t); }
Store(bcx, src, dst); Store(bcx, src, dst);
ret take_ty(bcx, dst, t); ret take_ty(bcx, dst, t);
} }
if ty::type_is_vec(ccx.tcx, t) {
if action == DROP_EXISTING { bcx = drop_ty(bcx, dst, t); }
let {bcx, val} = tvec::duplicate(bcx, src, t);
Store(bcx, val, dst);
ret bcx;
}
if ty::type_is_unique_box(ccx.tcx, t) {
if action == DROP_EXISTING { bcx = drop_ty(bcx, dst, t); }
check trans_uniq::type_is_unique_box(bcx, t);
ret trans_uniq::copy_val(bcx, dst, src, t);
}
if type_is_structural_or_param(ccx.tcx, t) { if type_is_structural_or_param(ccx.tcx, t) {
if action == DROP_EXISTING { bcx = drop_ty(bcx, dst, t); } if action == DROP_EXISTING { bcx = drop_ty(bcx, dst, t); }
bcx = memmove_ty(bcx, dst, src, t); bcx = memmove_ty(bcx, dst, src, t);

View file

@ -15,8 +15,7 @@ import trans::{
dest dest
}; };
export trans_uniq, make_free_glue, type_is_unique_box, copy_val, export trans_uniq, make_free_glue, type_is_unique_box, autoderef, duplicate;
autoderef, duplicate;
pure fn type_is_unique_box(bcx: @block_ctxt, ty: ty::t) -> bool { pure fn type_is_unique_box(bcx: @block_ctxt, ty: ty::t) -> bool {
ty::type_is_unique_box(bcx_tcx(bcx), ty) ty::type_is_unique_box(bcx_tcx(bcx), ty)
@ -77,19 +76,6 @@ fn content_ty(bcx: @block_ctxt, t: ty::t)
} }
} }
fn copy_val(cx: @block_ctxt, dst: ValueRef, src: ValueRef,
ty: ty::t) : type_is_unique_box(cx, ty) -> @block_ctxt {
let content_ty = content_ty(cx, ty);
let {bcx, val: llptr} = alloc_uniq(cx, ty);
Store(bcx, llptr, dst);
let src = load_if_immediate(bcx, src, content_ty);
let dst = llptr;
let bcx = trans::copy_val(bcx, INIT, dst, src, content_ty);
ret bcx;
}
fn autoderef(bcx: @block_ctxt, v: ValueRef, t: ty::t) fn autoderef(bcx: @block_ctxt, v: ValueRef, t: ty::t)
: type_is_unique_box(bcx, t) -> {v: ValueRef, t: ty::t} { : type_is_unique_box(bcx, t) -> {v: ValueRef, t: ty::t} {