Skip to content

Commit

Permalink
Merge pull request #17340 from JuliaLang/jb/checkb
Browse files Browse the repository at this point in the history
flatten the call chain of `checkbounds` a bit
  • Loading branch information
JeffBezanson authored Jul 9, 2016
2 parents 00de421 + 1f68ef8 commit dad6836
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,22 @@ Return `true` if the specified `indexes` are in bounds for the given `array`. Su
`AbstractArray` should specialize this method if they need to provide custom bounds checking
behaviors.
"""
function checkbounds(::Type{Bool}, A::AbstractArray, i::Integer)
@_inline_meta
checkindex(Bool, linearindices(A), i)
end
function checkbounds{T}(::Type{Bool}, A::Union{Array{T,1},Range{T}}, i::Integer)
@_inline_meta
(1 <= i) & (i <= length(A))
end
function checkbounds(::Type{Bool}, A::AbstractArray, I::AbstractArray{Bool})
@_inline_meta
checkbounds_logical(A, I)
end
function checkbounds(::Type{Bool}, A::AbstractArray, I...)
@_inline_meta
_chkbounds(A, I...)
checkbounds_indices(indices(A), I)
end
_chkbounds(A::AbstractArray, i::Integer) = (@_inline_meta; checkindex(Bool, linearindices(A), i))
_chkbounds(A::AbstractArray, I::AbstractArray{Bool}) = (@_inline_meta; checkbounds_logical(A, I))
_chkbounds(A::AbstractArray, I...) = (@_inline_meta; checkbounds_indices(indices(A), I))

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

0 comments on commit dad6836

Please sign in to comment.