@@ -355,14 +355,19 @@ module IteratorsMD
355
355
# CartesianIndices act as a multidimensional range, so cartesian indexing of CartesianIndices
356
356
# with compatible dimensions may be seen as indexing into the component ranges.
357
357
# 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} ,
359
359
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)
361
365
end
362
366
@propagate_inbounds function Base. getindex (iter:: CartesianIndices{N} ,
363
367
C:: CartesianIndices{N} ) where {N}
364
- CartesianIndices ( getindex . (iter. indices , C. indices) )
368
+ getindex (iter, C. indices... )
365
369
end
370
+ @inline Base. getindex (iter:: CartesianIndices{0} , :: CartesianIndices{0} ) = iter
366
371
367
372
# If dimensions permit, we may index into a CartesianIndices directly instead of constructing a SubArray wrapper
368
373
@propagate_inbounds function Base. view (c:: CartesianIndices{N} , r:: Vararg{Union{OrdinalRange{<:Integer, <:Integer}, Colon},N} ) where {N}
0 commit comments