@@ -355,14 +355,19 @@ module IteratorsMD
355355 # CartesianIndices act as a multidimensional range, so cartesian indexing of CartesianIndices
356356 # with compatible dimensions may be seen as indexing into the component ranges.
357357 # This may use the special indexing behavior implemented for ranges to return another CartesianIndices
358- @propagate_inbounds function Base. getindex (iter:: CartesianIndices{N,R} ,
358+ @inline function Base. getindex (iter:: CartesianIndices{N,R} ,
359359 I:: Vararg{Union{OrdinalRange{<:Integer, <:Integer}, Colon}, N} ) where {N,R}
360- CartesianIndices (getindex .(iter. indices, I))
360+ @boundscheck checkbounds (iter, I... )
361+ indices = map (iter. indices, I) do r, i
362+ @inbounds getindex (r, i)
363+ end
364+ CartesianIndices (indices)
361365 end
362366 @propagate_inbounds function Base. getindex (iter:: CartesianIndices{N} ,
363367 C:: CartesianIndices{N} ) where {N}
364- CartesianIndices ( getindex . (iter. indices , C. indices) )
368+ getindex (iter, C. indices... )
365369 end
370+ @inline Base. getindex (iter:: CartesianIndices{0} , :: CartesianIndices{0} ) = iter
366371
367372 # If dimensions permit, we may index into a CartesianIndices directly instead of constructing a SubArray wrapper
368373 @propagate_inbounds function Base. view (c:: CartesianIndices{N} , r:: Vararg{Union{OrdinalRange{<:Integer, <:Integer}, Colon},N} ) where {N}
0 commit comments