Skip to content

Commit adde889

Browse files
committed
Add a comment about the internal _inline_meta macro
1 parent 57f9e66 commit adde889

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

base/abstractarray.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,21 @@ end
337337

338338
zero{T}(x::AbstractArray{T}) = fill!(similar(x), zero(T))
339339

340-
## iteration support for arrays ##
340+
## iteration support for arrays by iterating over `eachindex` in the array ##
341+
# Allows fast iteration by default for both LinearFast and LinearSlow arrays
342+
343+
# While the definitions for LinearFast are all simple enough to inline on their
344+
# own, LinearSlow's CartesianRange is more complicated and requires explicit
345+
# inlining. The real @inline macro is not available this early in the bootstrap,
346+
# so this internal macro splices the meta Expr directly into the function body.
341347
macro _inline_meta()
342348
Expr(:meta, :inline)
343349
end
344350
start(A::AbstractArray) = (@_inline_meta(); itr = eachindex(A); (itr, start(itr)))
345351
next(A::AbstractArray,i) = (@_inline_meta(); (idx, s) = next(i[1], i[2]); (A[idx], (i[1], s)))
346352
done(A::AbstractArray,i) = done(i[1], i[2])
347353

348-
# eachindex iterates over all indices. LinearSlow is later in bootstrap
354+
# eachindex iterates over all indices. LinearSlow definitions are later.
349355
eachindex(A::AbstractArray) = (@_inline_meta; eachindex(linearindexing(A), A))
350356
eachindex(::LinearFast, A::AbstractArray) = 1:length(A)
351357

0 commit comments

Comments
 (0)