Skip to content

Commit dad6836

Browse files
authored
Merge pull request #17340 from JuliaLang/jb/checkb
flatten the call chain of `checkbounds` a bit
2 parents 00de421 + 1f68ef8 commit dad6836

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

base/abstractarray.jl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,22 @@ Return `true` if the specified `indexes` are in bounds for the given `array`. Su
190190
`AbstractArray` should specialize this method if they need to provide custom bounds checking
191191
behaviors.
192192
"""
193+
function checkbounds(::Type{Bool}, A::AbstractArray, i::Integer)
194+
@_inline_meta
195+
checkindex(Bool, linearindices(A), i)
196+
end
197+
function checkbounds{T}(::Type{Bool}, A::Union{Array{T,1},Range{T}}, i::Integer)
198+
@_inline_meta
199+
(1 <= i) & (i <= length(A))
200+
end
201+
function checkbounds(::Type{Bool}, A::AbstractArray, I::AbstractArray{Bool})
202+
@_inline_meta
203+
checkbounds_logical(A, I)
204+
end
193205
function checkbounds(::Type{Bool}, A::AbstractArray, I...)
194206
@_inline_meta
195-
_chkbounds(A, I...)
207+
checkbounds_indices(indices(A), I)
196208
end
197-
_chkbounds(A::AbstractArray, i::Integer) = (@_inline_meta; checkindex(Bool, linearindices(A), i))
198-
_chkbounds(A::AbstractArray, I::AbstractArray{Bool}) = (@_inline_meta; checkbounds_logical(A, I))
199-
_chkbounds(A::AbstractArray, I...) = (@_inline_meta; checkbounds_indices(indices(A), I))
200209

201210
checkbounds_indices(::Tuple{}, ::Tuple{}) = true
202211
checkbounds_indices(::Tuple{}, I::Tuple{Any}) = (@_inline_meta; checkindex(Bool, 1:1, I[1]))

0 commit comments

Comments
 (0)