Skip to content

Commit b6a60dd

Browse files
authored
use checkbounds instead of in in copyto! (#28146)
1 parent 435f0a2 commit b6a60dd

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

base/abstractarray.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ copyto!(dest::AbstractArray, src::AbstractArray) =
733733

734734
function copyto!(::IndexStyle, dest::AbstractArray, ::IndexStyle, src::AbstractArray)
735735
destinds, srcinds = LinearIndices(dest), LinearIndices(src)
736-
isempty(srcinds) || (first(srcinds) destinds && last(srcinds) destinds) ||
736+
isempty(srcinds) || (checkbounds(Bool, destinds, first(srcinds)) && checkbounds(Bool, destinds, last(srcinds))) ||
737737
throw(BoundsError(dest, srcinds))
738738
@inbounds for i in srcinds
739739
dest[i] = src[i]
@@ -743,7 +743,7 @@ end
743743

744744
function copyto!(::IndexStyle, dest::AbstractArray, ::IndexCartesian, src::AbstractArray)
745745
destinds, srcinds = LinearIndices(dest), LinearIndices(src)
746-
isempty(srcinds) || (first(srcinds) destinds && last(srcinds) destinds) ||
746+
isempty(srcinds) || (checkbounds(Bool, destinds, first(srcinds)) && checkbounds(Bool, destinds, last(srcinds))) ||
747747
throw(BoundsError(dest, srcinds))
748748
i = 0
749749
@inbounds for a in src
@@ -758,7 +758,7 @@ end
758758

759759
function copyto!(dest::AbstractArray, dstart::Integer, src::AbstractArray, sstart::Integer)
760760
srcinds = LinearIndices(src)
761-
sstart srcinds || throw(BoundsError(src, sstart))
761+
checkbounds(Bool, srcinds, sstart) || throw(BoundsError(src, sstart))
762762
copyto!(dest, dstart, src, sstart, last(srcinds)-sstart+1)
763763
end
764764

@@ -768,8 +768,8 @@ function copyto!(dest::AbstractArray, dstart::Integer,
768768
n == 0 && return dest
769769
n < 0 && throw(ArgumentError(string("tried to copy n=", n, " elements, but n should be nonnegative")))
770770
destinds, srcinds = LinearIndices(dest), LinearIndices(src)
771-
(dstart destinds && dstart+n-1 destinds) || throw(BoundsError(dest, dstart:dstart+n-1))
772-
(sstart srcinds && sstart+n-1 srcinds) || throw(BoundsError(src, sstart:sstart+n-1))
771+
(checkbounds(Bool, destinds, dstart) && checkbounds(Bool, destinds, dstart+n-1)) || throw(BoundsError(dest, dstart:dstart+n-1))
772+
(checkbounds(Bool, srcinds, sstart) && checkbounds(Bool, srcinds, sstart+n-1)) || throw(BoundsError(src, sstart:sstart+n-1))
773773
@inbounds for i = 0:(n-1)
774774
dest[dstart+i] = src[sstart+i]
775775
end

0 commit comments

Comments
 (0)