@@ -354,11 +354,6 @@ fn trans_append(cx: &@block_ctxt, t: ty::t, orig_lhs: ValueRef,
354
354
355
355
let unit_ty = ty:: sequence_element_type ( bcx_tcx ( cx) , t) ;
356
356
let llunitty = type_of_or_i8 ( cx, unit_ty) ;
357
- alt ty:: struct ( bcx_tcx ( cx) , t) {
358
- ty:: ty_istr. { }
359
- ty:: ty_vec ( _) { }
360
- _ { bcx_tcx( cx) . sess . bug ( "non-istr/ivec in trans_append" ) ; }
361
- }
362
357
363
358
let rs = size_of ( cx, unit_ty) ;
364
359
let bcx = rs. bcx ;
@@ -381,10 +376,31 @@ fn trans_append(cx: &@block_ctxt, t: ty::t, orig_lhs: ValueRef,
381
376
let rhs_len = rhs_len_and_data. len ;
382
377
let rhs_data = rhs_len_and_data. data ;
383
378
bcx = rhs_len_and_data. bcx ;
384
- rs = reserve_space ( bcx, llunitty, lhs, rhs_len) ;
385
- let lhs_data = rs. val ;
379
+
380
+ let have_istrs = alt ty:: struct ( bcx_tcx ( cx) , t) {
381
+ ty:: ty_istr. { true }
382
+ ty:: ty_vec ( _) { false }
383
+ _ { bcx_tcx( cx) . sess . bug ( "non-istr/ivec in trans_append" ) ; }
384
+ } ;
385
+
386
+ let extra_len = if have_istrs {
387
+ // Only need one of the nulls
388
+ bcx. build . Sub ( rhs_len, C_uint ( 1 u) )
389
+ } else { rhs_len } ;
390
+
391
+ rs = reserve_space ( bcx, llunitty, lhs, extra_len) ;
386
392
bcx = rs. bcx ;
387
393
394
+ let lhs_data = if have_istrs {
395
+ let lhs_data = rs. val ;
396
+ let lhs_data_without_null_ptr = alloca ( bcx, T_ptr ( llunitty) ) ;
397
+ incr_ptr ( bcx, lhs_data, C_int ( -1 ) ,
398
+ lhs_data_without_null_ptr) ;
399
+ bcx. build . Load ( lhs_data_without_null_ptr)
400
+ } else {
401
+ rs. val
402
+ } ;
403
+
388
404
// If rhs is lhs then our rhs pointer may have changed
389
405
rhs_len_and_data = get_len_and_data ( bcx, rhs, unit_ty) ;
390
406
rhs_data = rhs_len_and_data. data ;
0 commit comments