Skip to content

Commit 20c4be5

Browse files
committed
use plain map
1 parent defc214 commit 20c4be5

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

base/multidimensional.jl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,16 +358,14 @@ module IteratorsMD
358358
CartesianIndex()
359359
end
360360
@inline function Base.getindex(iter::CartesianIndices{N,R}, I::Vararg{Int, N}) where {N,R}
361-
# Eagerly do boundscheck before calculating each item of the CartesianIndex,
362-
# this generates inlined codes for `_get_cartesianindex` and furthermore enables SIMD
361+
# Eagerly do boundscheck before calculating each item of the CartesianIndex so that
362+
# we can pass `@inbounds` hint to inside the map and generates more efficient SIMD codes
363363
@boundscheck checkbounds(iter, I...)
364-
@inbounds CartesianIndex(_get_cartesianindex(iter.indices, I))
365-
end
366-
@propagate_inbounds _get_cartesianindex(indices, I) = _get_cartesianindex(getindex(first(indices), first(I)), tail(indices), tail(I))
367-
@propagate_inbounds function _get_cartesianindex(out, indices, I)
368-
_get_cartesianindex((out..., getindex(first(indices), first(I))), tail(indices), tail(I))
364+
index = map(iter.indices, I) do r, i
365+
@inbounds getindex(r, i)
366+
end
367+
CartesianIndex(index)
369368
end
370-
@inline _get_cartesianindex(out, ::Tuple{}, ::Tuple{}) = out
371369

372370
# CartesianIndices act as a multidimensional range, so cartesian indexing of CartesianIndices
373371
# with compatible dimensions may be seen as indexing into the component ranges.

0 commit comments

Comments
 (0)