| ... | ... | @@ -15237,6 +15237,76 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15237 | 15237 | .flags = .{ .address_space = ptr_as }, |
| 15238 | 15238 | }); |
| 15239 | 15239 | |
| 15240 | // if both the source and destination are arrays |
| 15241 | // we can hot path via a memcpy. |
| 15242 | if (lhs_ty.zigTypeTag(zcu) == .pointer and |
| 15243 | rhs_ty.zigTypeTag(zcu) == .pointer) |
| 15244 | { |
| 15245 | const slice_ty = try pt.ptrTypeSema(.{ |
| 15246 | .child = resolved_elem_ty.toIntern(), |
| 15247 | .flags = .{ |
| 15248 | .size = .Slice, |
| 15249 | .address_space = ptr_as, |
| 15250 | }, |
| 15251 | }); |
| 15252 | const many_ty = try pt.ptrTypeSema(.{ |
| 15253 | .child = resolved_elem_ty.toIntern(), |
| 15254 | .flags = .{ |
| 15255 | .size = .Many, |
| 15256 | .address_space = ptr_as, |
| 15257 | }, |
| 15258 | }); |
| 15259 | const slice_ty_ref = Air.internedToRef(slice_ty.toIntern()); |
| 15260 | |
| 15261 | // lhs_dest_slice = dest[0..lhs.len] |
| 15262 | const lhs_len_ref = try pt.intRef(Type.usize, lhs_len); |
| 15263 | const lhs_dest_slice = try block.addInst(.{ |
| 15264 | .tag = .slice, |
| 15265 | .data = .{ .ty_pl = .{ |
| 15266 | .ty = slice_ty_ref, |
| 15267 | .payload = try sema.addExtra(Air.Bin{ |
| 15268 | .lhs = alloc, |
| 15269 | .rhs = lhs_len_ref, |
| 15270 | }), |
| 15271 | } }, |
| 15272 | }); |
| 15273 | _ = try block.addBinOp(.memcpy, lhs_dest_slice, lhs); |
| 15274 | |
| 15275 | // rhs_dest_slice = dest[lhs.len..][0..rhs.len] |
| 15276 | const rhs_len_ref = try pt.intRef(Type.usize, rhs_len); |
| 15277 | const rhs_dest_offset = try block.addInst(.{ |
| 15278 | .tag = .ptr_add, |
| 15279 | .data = .{ .ty_pl = .{ |
| 15280 | .ty = Air.internedToRef(many_ty.toIntern()), |
| 15281 | .payload = try sema.addExtra(Air.Bin{ |
| 15282 | .lhs = alloc, |
| 15283 | .rhs = lhs_len_ref, |
| 15284 | }), |
| 15285 | } }, |
| 15286 | }); |
| 15287 | const rhs_dest_slice = try block.addInst(.{ |
| 15288 | .tag = .slice, |
| 15289 | .data = .{ .ty_pl = .{ |
| 15290 | .ty = slice_ty_ref, |
| 15291 | .payload = try sema.addExtra(Air.Bin{ |
| 15292 | .lhs = rhs_dest_offset, |
| 15293 | .rhs = rhs_len_ref, |
| 15294 | }), |
| 15295 | } }, |
| 15296 | }); |
| 15297 | |
| 15298 | _ = try block.addBinOp(.memcpy, rhs_dest_slice, rhs); |
| 15299 | |
| 15300 | if (res_sent_val) |sent_val| { |
| 15301 | const elem_index = try pt.intRef(Type.usize, result_len); |
| 15302 | const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty); |
| 15303 | const init = Air.internedToRef((try pt.getCoerced(sent_val, lhs_info.elem_type)).toIntern()); |
| 15304 | try sema.storePtr2(block, src, elem_ptr, src, init, lhs_src, .store); |
| 15305 | } |
| 15306 | |
| 15307 | return alloc; |
| 15308 | } |
| 15309 | |
| 15240 | 15310 | var elem_i: u32 = 0; |
| 15241 | 15311 | while (elem_i < lhs_len) : (elem_i += 1) { |
| 15242 | 15312 | const elem_index = try pt.intRef(Type.usize, elem_i); |