diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 81b9e9daa4932..2a0b8ccc8e26f 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -373,9 +373,16 @@ zero{T}(x::AbstractArray{T}) = fill!(similar(x), zero(T)) # While the definitions for LinearFast are all simple enough to inline on their # own, LinearSlow's CartesianRange is more complicated and requires explicit # inlining. -start(A::AbstractArray) = (@_inline_meta(); itr = eachindex(A); (itr, start(itr))) -next(A::AbstractArray,i) = (@_inline_meta(); (idx, s) = next(i[1], i[2]); (A[idx], (i[1], s))) -done(A::AbstractArray,i) = done(i[1], i[2]) +start(A::AbstractArray) = (@_inline_meta(); _start(linearindexing(A), A)) +_start(::LinearFast, A::AbstractArray) = 1 +_start(::LinearSlow, A::AbstractArray) = (@_inline_meta(); itr = eachindex(A); (itr, start(itr))) + +next(A::AbstractArray,i) = (@_inline_meta(); _next(A,i)) +_next(A::AbstractArray,i) = (@_inline_meta(); (idx, s) = next(i[1], i[2]); (A[idx], (i[1], s))) +_next(A::AbstractArray,i::Int) = (A[i],i+1) +done(A::AbstractArray,i) = (@_inline_meta(); _done(A, i)) +_done(A::AbstractArray,i) = done(i[1], i[2]) +_done(A::AbstractArray,i::Int) = i == length(A)+1 # eachindex iterates over all indices. LinearSlow definitions are later. eachindex(A::AbstractArray) = (@_inline_meta(); eachindex(linearindexing(A), A)) diff --git a/base/array.jl b/base/array.jl index 9691b325c3541..0113298104268 100644 --- a/base/array.jl +++ b/base/array.jl @@ -210,11 +210,6 @@ Return an array of all items in a collection. For associative collections, retur """ collect(itr) = collect(eltype(itr), itr) -## Iteration ## -start(A::Array) = 1 -next(a::Array,i) = (a[i],i+1) -done(a::Array,i) = i == length(a)+1 - ## Indexing: getindex ## # This is more complicated than it needs to be in order to get Win64 through bootstrap