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