@@ -891,13 +891,12 @@ See also [`copyto!`](@ref).
891891 is available from the `Future` standard library as `Future.copy!`.
892892"""
893893function copy! (dst:: AbstractVector , src:: AbstractVector )
894+ firstindex (dst) == firstindex (src) || throw (ArgumentError (
895+ " vectors must have the same offset for copy! (consider using `copyto!`)" ))
894896 if length (dst) != length (src)
895897 resize! (dst, length (src))
896898 end
897- for i in eachindex (dst, src)
898- @inbounds dst[i] = src[i]
899- end
900- dst
899+ copyto! (dst, src)
901900end
902901
903902function copy! (dst:: AbstractArray , src:: AbstractArray )
@@ -1108,8 +1107,9 @@ function copyto!(dest::AbstractArray, dstart::Integer,
11081107 destinds, srcinds = LinearIndices (dest), LinearIndices (src)
11091108 (checkbounds (Bool, destinds, dstart) && checkbounds (Bool, destinds, dstart+ n- 1 )) || throw (BoundsError (dest, dstart: dstart+ n- 1 ))
11101109 (checkbounds (Bool, srcinds, sstart) && checkbounds (Bool, srcinds, sstart+ n- 1 )) || throw (BoundsError (src, sstart: sstart+ n- 1 ))
1111- @inbounds for i = 0 : (n- 1 )
1112- dest[dstart+ i] = src[sstart+ i]
1110+ src′ = unalias (dest, src)
1111+ @inbounds for i = 0 : n- 1
1112+ dest[dstart+ i] = src′[sstart+ i]
11131113 end
11141114 return dest
11151115end
@@ -1131,11 +1131,12 @@ function copyto!(B::AbstractVecOrMat{R}, ir_dest::AbstractRange{Int}, jr_dest::A
11311131 end
11321132 @boundscheck checkbounds (B, ir_dest, jr_dest)
11331133 @boundscheck checkbounds (A, ir_src, jr_src)
1134+ A′ = unalias (B, A)
11341135 jdest = first (jr_dest)
11351136 for jsrc in jr_src
11361137 idest = first (ir_dest)
11371138 for isrc in ir_src
1138- @inbounds B[idest,jdest] = A[isrc,jsrc]
1139+ @inbounds B[idest,jdest] = A′ [isrc,jsrc]
11391140 idest += step (ir_dest)
11401141 end
11411142 jdest += step (jr_dest)
0 commit comments