Skip to content

Commit

Permalink
Specialize iteration for Array
Browse files Browse the repository at this point in the history
Explicitly inline next to ensure it inlines for LinearSlow types. Fix test failure.
  • Loading branch information
mbauman committed Apr 1, 2015
1 parent 1450eeb commit 39ef7c4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,11 @@ end
zero{T}(x::AbstractArray{T}) = fill!(similar(x), zero(T))

## iteration support for arrays ##

macro _inline_meta()
Expr(:meta, :inline)
end
start(A::AbstractArray) = (itr = eachindex(A); (itr, start(itr)))
next(A::AbstractArray,i) = ((idx, s) = next(i[1], i[2]); (A[idx], (i[1], s)))
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])

# eachindex iterates over all indices. LinearSlow is later in bootstrap
Expand Down
5 changes: 5 additions & 0 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ end

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))

## Indexing: getindex ##

getindex(a::Array) = arrayref(a,1)
Expand Down
2 changes: 1 addition & 1 deletion base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ function copy!{T,N}(dest::AbstractArray{T,N}, src::AbstractArray{T,N})
break
end
end
if samesize
if samesize && linearindexing(dest) == linearindexing(src)
for I in eachindex(dest)
@inbounds dest[I] = src[I]
end
Expand Down

0 comments on commit 39ef7c4

Please sign in to comment.