From b6a60dd6601a6947e00a0a77decd283248ba8a7f Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Tue, 17 Jul 2018 22:09:11 +0200 Subject: [PATCH] use `checkbounds` instead of `in` in copyto! (#28146) --- base/abstractarray.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 91353bf5e98c7..3752068ef9192 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -733,7 +733,7 @@ copyto!(dest::AbstractArray, src::AbstractArray) = function copyto!(::IndexStyle, dest::AbstractArray, ::IndexStyle, src::AbstractArray) destinds, srcinds = LinearIndices(dest), LinearIndices(src) - isempty(srcinds) || (first(srcinds) ∈ destinds && last(srcinds) ∈ destinds) || + isempty(srcinds) || (checkbounds(Bool, destinds, first(srcinds)) && checkbounds(Bool, destinds, last(srcinds))) || throw(BoundsError(dest, srcinds)) @inbounds for i in srcinds dest[i] = src[i] @@ -743,7 +743,7 @@ end function copyto!(::IndexStyle, dest::AbstractArray, ::IndexCartesian, src::AbstractArray) destinds, srcinds = LinearIndices(dest), LinearIndices(src) - isempty(srcinds) || (first(srcinds) ∈ destinds && last(srcinds) ∈ destinds) || + isempty(srcinds) || (checkbounds(Bool, destinds, first(srcinds)) && checkbounds(Bool, destinds, last(srcinds))) || throw(BoundsError(dest, srcinds)) i = 0 @inbounds for a in src @@ -758,7 +758,7 @@ end function copyto!(dest::AbstractArray, dstart::Integer, src::AbstractArray, sstart::Integer) srcinds = LinearIndices(src) - sstart ∈ srcinds || throw(BoundsError(src, sstart)) + checkbounds(Bool, srcinds, sstart) || throw(BoundsError(src, sstart)) copyto!(dest, dstart, src, sstart, last(srcinds)-sstart+1) end @@ -768,8 +768,8 @@ function copyto!(dest::AbstractArray, dstart::Integer, n == 0 && return dest n < 0 && throw(ArgumentError(string("tried to copy n=", n, " elements, but n should be nonnegative"))) destinds, srcinds = LinearIndices(dest), LinearIndices(src) - (dstart ∈ destinds && dstart+n-1 ∈ destinds) || throw(BoundsError(dest, dstart:dstart+n-1)) - (sstart ∈ srcinds && sstart+n-1 ∈ srcinds) || throw(BoundsError(src, sstart:sstart+n-1)) + (checkbounds(Bool, destinds, dstart) && checkbounds(Bool, destinds, dstart+n-1)) || throw(BoundsError(dest, dstart:dstart+n-1)) + (checkbounds(Bool, srcinds, sstart) && checkbounds(Bool, srcinds, sstart+n-1)) || throw(BoundsError(src, sstart:sstart+n-1)) @inbounds for i = 0:(n-1) dest[dstart+i] = src[sstart+i] end