@@ -368,14 +368,19 @@ module IteratorsMD
368
368
# CartesianIndices act as a multidimensional range, so cartesian indexing of CartesianIndices
369
369
# with compatible dimensions may be seen as indexing into the component ranges.
370
370
# This may use the special indexing behavior implemented for ranges to return another CartesianIndices
371
- @propagate_inbounds function Base. getindex (iter:: CartesianIndices{N,R} ,
371
+ @inline function Base. getindex (iter:: CartesianIndices{N,R} ,
372
372
I:: Vararg{Union{OrdinalRange{<:Integer, <:Integer}, Colon}, N} ) where {N,R}
373
- CartesianIndices (getindex .(iter. indices, I))
373
+ @boundscheck checkbounds (iter, I... )
374
+ indices = map (iter. indices, I) do r, i
375
+ @inbounds getindex (r, i)
376
+ end
377
+ CartesianIndices (indices)
374
378
end
375
379
@propagate_inbounds function Base. getindex (iter:: CartesianIndices{N} ,
376
380
C:: CartesianIndices{N} ) where {N}
377
- CartesianIndices ( getindex . (iter. indices , C. indices) )
381
+ getindex (iter, C. indices... )
378
382
end
383
+ @inline Base. getindex (iter:: CartesianIndices{0} , :: CartesianIndices{0} ) = iter
379
384
380
385
# If dimensions permit, we may index into a CartesianIndices directly instead of constructing a SubArray wrapper
381
386
@propagate_inbounds function Base. view (c:: CartesianIndices{N} , r:: Vararg{Union{OrdinalRange{<:Integer, <:Integer}, Colon},N} ) where {N}
0 commit comments