From 17c649b49537db14bf30b551059fa9ced24d02dc Mon Sep 17 00:00:00 2001 From: Matt Bauman Date: Sun, 15 Mar 2015 23:45:43 -0400 Subject: [PATCH] More consistent inlining strategy: The most important thing here is to ensure that scalar indexing never allocates and always inlines. --- base/abstractarray.jl | 4 ++-- base/multidimensional.jl | 11 ++++------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 9ebb393bd63c7..defbab044df41 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -490,11 +490,11 @@ setindex!(t::AbstractArray, x) = throw(MethodError(setindex!, (t, x))) stagedfunction getindex(A::AbstractArray, I...) Isplat = Expr[:(I[$d]) for d = 1:length(I)] - :(_getindex(linearindexing(A), A, $(Isplat...))) + :($(Expr(:meta, :inline)); _getindex(linearindexing(A), A, $(Isplat...))) end stagedfunction unsafe_getindex(A::AbstractArray, I...) Isplat = Expr[:(I[$d]) for d = 1:length(I)] - :(_unsafe_getindex(linearindexing(A), A, $(Isplat...))) + :($(Expr(:meta, :inline)); _unsafe_getindex(linearindexing(A), A, $(Isplat...))) end ## Internal defitions _getindex(::LinearFast, A::AbstractArray) = getindex(A, 1) diff --git a/base/multidimensional.jl b/base/multidimensional.jl index c79a633e08e6e..432e5e576d00c 100644 --- a/base/multidimensional.jl +++ b/base/multidimensional.jl @@ -219,17 +219,17 @@ end # sensitive. _getindex(::LinearFast, A::AbstractArray, index::CartesianIndex{1}) = getindex(A, index[1]) stagedfunction _getindex{N}(l::LinearFast, A::AbstractArray, index::CartesianIndex{N}) - :(@ncall $N _getindex l A d->index[d]) + :($(Expr(:meta, :inline)); @ncall $N _getindex l A d->index[d]) end stagedfunction _getindex{N}(::LinearSlow, A::AbstractArray, index::CartesianIndex{N}) - :(@ncall $N getindex A d->index[d]) + :($(Expr(:meta, :inline)); @ncall $N getindex A d->index[d]) end _unsafe_getindex(::LinearFast, A::AbstractArray, index::CartesianIndex{1}) = unsafe_getindex(A, index[1]) stagedfunction _unsafe_getindex{N}(l::LinearFast, A::AbstractArray, index::CartesianIndex{N}) - :(@ncall $N _unsafe_getindex l A d->index[d]) + :($(Expr(:meta, :inline)); @ncall $N _unsafe_getindex l A d->index[d]) end stagedfunction _unsafe_getindex{N}(::LinearSlow, A::AbstractArray, index::CartesianIndex{N}) - :(@ncall $N unsafe_getindex A d->index[d]) + :($(Expr(:meta, :inline)); @ncall $N unsafe_getindex A d->index[d]) end # Indexing with just one array is always linear in the source, fast or slow @@ -254,7 +254,6 @@ stagedfunction _unsafe_getindex!(::LinearFast, dest::AbstractArray, ::LinearFast N = length(I) Isplat = Expr[:(I[$d]) for d = 1:N] quote - $(Expr(:meta, :inline)) stride_1 = 1 @nexprs $N d->(stride_{d+1} = stride_d*size(src, d)) $(symbol(:offset_, N)) = 1 @@ -271,7 +270,6 @@ stagedfunction _unsafe_getindex!(::LinearFast, dest::AbstractArray, ::LinearSlow N = length(I) Isplat = Expr[:(I[$d]) for d = 1:N] quote - $(Expr(:meta, :inline)) k = 1 @nloops $N i dest d->(@inbounds j_d = unsafe_getindex(I[d], i_d)) begin v = @ncall $N unsafe_getindex src j @@ -287,7 +285,6 @@ stagedfunction _unsafe_getindex!(::LinearSlow, dest::AbstractArray, ::LinearInde N = length(I) Isplat = Expr[:(I[$d]) for d = 1:N] quote - $(Expr(:meta, :inline)) @nloops $N i dest d->(@inbounds j_d = unsafe_getindex(I[d], i_d)) begin v = @ncall $N unsafe_getindex src j @ncall $N unsafe_setindex! dest v i