diff options
| author | Mark-Simulacrum <mark.simulacrum@gmail.com> | 2016-12-15 10:32:12 -0700 |
|---|---|---|
| committer | Mark Simulacrum <mark.simulacrum@gmail.com> | 2016-12-20 20:02:51 -0700 |
| commit | 6710af358051725342d4eec11e0c423aabd98511 (patch) | |
| tree | b1038639b4172ef79e2f66b2c8cecd8ff7efb995 /src | |
| parent | 6441c977cb387b2d057dc6e3b704b475afd97137 (diff) | |
| download | rust-6710af358051725342d4eec11e0c423aabd98511.tar.gz rust-6710af358051725342d4eec11e0c423aabd98511.zip | |
Slightly simplify tvec::slice_for_each
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_trans/tvec.rs | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/src/librustc_trans/tvec.rs b/src/librustc_trans/tvec.rs index 904e3765017..36762885cc9 100644 --- a/src/librustc_trans/tvec.rs +++ b/src/librustc_trans/tvec.rs @@ -15,16 +15,13 @@ use llvm::ValueRef; use common::*; use rustc::ty::Ty; -pub fn slice_for_each<'blk, 'tcx, F>(bcx: &BlockAndBuilder<'blk, 'tcx>, - data_ptr: ValueRef, - unit_ty: Ty<'tcx>, - len: ValueRef, - f: F) - -> BlockAndBuilder<'blk, 'tcx> - where F: FnOnce(&BlockAndBuilder<'blk, 'tcx>, ValueRef) -{ - let fcx = bcx.fcx(); - +pub fn slice_for_each<'blk, 'tcx, F>( + bcx: &BlockAndBuilder<'blk, 'tcx>, + data_ptr: ValueRef, + unit_ty: Ty<'tcx>, + len: ValueRef, + f: F +) -> BlockAndBuilder<'blk, 'tcx> where F: FnOnce(&BlockAndBuilder<'blk, 'tcx>, ValueRef) { // Special-case vectors with elements of size 0 so they don't go out of bounds (#9890) let zst = type_is_zero_size(bcx.ccx(), unit_ty); let add = |bcx: &BlockAndBuilder, a, b| if zst { @@ -33,9 +30,9 @@ pub fn slice_for_each<'blk, 'tcx, F>(bcx: &BlockAndBuilder<'blk, 'tcx>, bcx.inbounds_gep(a, &[b]) }; - let body_bcx = fcx.build_new_block("slice_loop_body"); - let next_bcx = fcx.build_new_block("slice_loop_next"); - let header_bcx = fcx.build_new_block("slice_loop_header"); + let body_bcx = bcx.fcx().build_new_block("slice_loop_body"); + let next_bcx = bcx.fcx().build_new_block("slice_loop_next"); + let header_bcx = bcx.fcx().build_new_block("slice_loop_header"); let start = if zst { C_uint(bcx.ccx(), 0usize) @@ -51,13 +48,7 @@ pub fn slice_for_each<'blk, 'tcx, F>(bcx: &BlockAndBuilder<'blk, 'tcx>, header_bcx.cond_br(keep_going, body_bcx.llbb(), next_bcx.llbb()); f(&body_bcx, if zst { data_ptr } else { current }); - // FIXME(simulacrum): The code below is identical to the closure (add) above, but using the - // closure doesn't compile due to body_bcx still being borrowed when dropped. - let next = if zst { - body_bcx.add(current, C_uint(bcx.ccx(), 1usize)) - } else { - body_bcx.inbounds_gep(current, &[C_uint(bcx.ccx(), 1usize)]) - }; + let next = add(&body_bcx, current, C_uint(bcx.ccx(), 1usize)); body_bcx.add_incoming_to_phi(current, next, body_bcx.llbb()); body_bcx.br(header_bcx.llbb()); next_bcx |
