@@ -276,8 +276,6 @@ source and `do` in the destination (1-indexed).
276276The `unsafe` prefix on this function indicates that no validation is performed to ensure
277277that N is inbounds on either array. Incorrect usage may corrupt or segfault your program, in
278278the same manner as C.
279-
280- $(_DOCS_ALIASING_WARNING)
281279"""
282280function unsafe_copyto! (dest:: Array , doffs, src:: Array , soffs, n)
283281 n == 0 && return dest
@@ -291,24 +289,26 @@ end
291289Copy `N` elements from collection `src` starting at the linear index `so`, to array `dest` starting at
292290the index `do`. Return `dest`.
293291"""
294- function copyto! (dest:: Array , doffs:: Integer , src:: Array , soffs:: Integer , n:: Integer )
295- return _copyto_impl! (dest, doffs, src, soffs, n)
296- end
292+ copyto! (dest:: Array , doffs:: Integer , src:: Array , soffs:: Integer , n:: Integer ) = _copyto_impl! (dest, doffs, src, soffs, n )
293+ copyto! (dest :: Array , doffs :: Integer , src :: Memory , soffs :: Integer , n :: Integer ) = _copyto_impl! (dest, doffs, src, soffs, n)
294+ copyto! (dest :: Memory , doffs :: Integer , src :: Array , soffs :: Integer , n :: Integer ) = _copyto_impl! (dest, doffs, src, soffs, n)
297295
298296# this is only needed to avoid possible ambiguities with methods added in some packages
299- function copyto! (dest:: Array{T} , doffs:: Integer , src:: Array{T} , soffs:: Integer , n:: Integer ) where T
300- return _copyto_impl! (dest, doffs, src, soffs, n)
301- end
297+ copyto! (dest:: Array{T} , doffs:: Integer , src:: Array{T} , soffs:: Integer , n:: Integer ) where {T} = _copyto_impl! (dest, doffs, src, soffs, n)
302298
303- function _copyto_impl! (dest:: Array , doffs:: Integer , src:: Array , soffs:: Integer , n:: Integer )
299+ function _copyto_impl! (dest:: Union{ Array,Memory} , doffs:: Integer , src:: Union{ Array,Memory} , soffs:: Integer , n:: Integer )
304300 n == 0 && return dest
305301 n > 0 || _throw_argerror (" Number of elements to copy must be non-negative." )
306302 @boundscheck checkbounds (dest, doffs: doffs+ n- 1 )
307303 @boundscheck checkbounds (src, soffs: soffs+ n- 1 )
308- unsafe_copyto! (dest, doffs, src, soffs, n)
304+ @inbounds let dest = GenericMemoryRef (dest isa Array ? getfield (dest, :ref ) : dest, doffs)
305+ src = GenericMemoryRef (src isa Array ? getfield (src, :ref ) : src, soffs)
306+ unsafe_copyto! (dest, src, n)
307+ end
309308 return dest
310309end
311310
311+
312312# Outlining this because otherwise a catastrophic inference slowdown
313313# occurs, see discussion in #27874.
314314# It is also mitigated by using a constant string.
0 commit comments