Skip to content

Commit 07a68df

Browse files
committed
rustc: Skip null when translating string concatenation
1 parent 08eabde commit 07a68df

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/comp/middle/trans_vec.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ fn trans_concat(&@block_ctxt cx, &dest in_dest, &span sp, ty::t t,
127127
// TODO: Detect "a + [ literal ]" and optimize to copying the literal
128128
// elements in directly.
129129

130-
// Translate the LHS and RHS. Pull out their length and data.
131130
auto t = ty::expr_ty(bcx_tcx(bcx), lhs);
131+
auto skip_null = ty::type_is_str(bcx_tcx(bcx), t);
132+
133+
// Translate the LHS and RHS. Pull out their length and data.
132134
auto lhs_tmp = trans_dps::dest_alias(bcx_tcx(bcx), t);
133135
bcx = trans_dps::trans_expr(bcx, lhs_tmp, lhs);
134136
auto lllhsptr = trans_dps::dest_ptr(lhs_tmp);
@@ -142,6 +144,8 @@ fn trans_concat(&@block_ctxt cx, &dest in_dest, &span sp, ty::t t,
142144
r0 = get_len_and_data(bcx, t, llrhsptr);
143145
bcx = r0._0; auto llrhslen = r0._1; auto llrhsdata = r0._2;
144146

147+
if skip_null { lllhslen = bcx.build.Sub(lllhslen, C_int(1)); }
148+
145149
// Allocate the destination.
146150
auto r1 = trans_dps::spill_alias(bcx, in_dest, t);
147151
bcx = r1._0; auto dest = r1._1;

src/comp/middle/ty.rs

+1
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,7 @@ fn type_is_sequence(&ctxt cx, &t ty) -> bool {
915915
fn type_is_str(&ctxt cx, &t ty) -> bool {
916916
alt (struct(cx, ty)) {
917917
case (ty_str) { ret true; }
918+
case (ty_istr) { ret true; }
918919
case (_) { ret false; }
919920
}
920921
}

0 commit comments

Comments
 (0)