Skip to content

Commit

Permalink
Fast path for inferred cases
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloferz committed Sep 27, 2016
1 parent 52479fc commit 5d4cd87
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ end

# broadcast methods that dispatch on the type found by inference
function _broadcast_t(f, ::Type{Any}, shape, iter, As...)
if isempty(iter)
return similar(Array{Any}, shape)
end
nargs = length(As)
keeps, Idefaults = map_newindexer(shape, As)
st = start(iter)
Expand Down Expand Up @@ -272,14 +275,16 @@ ziptype(A, B) = Zip2{Tuple{eltype(A)},Tuple{eltype(B)}}

# broadcast methods that dispatch on the type of the final container
@inline function broadcast_c(f, ::Type{Array}, As...)
S = _default_eltype(Generator{ziptype(As...),ftype(f, As...)})
T = _default_eltype(Generator{ziptype(As...),ftype(f, As...)})
shape = broadcast_indices(As...)
iter = CartesianRange(shape)
if isleaftype(T)
return _broadcast_t(f, T, shape, iter, As...)
end
if isempty(iter)
return similar(Array{S}, shape)
return similar(Array{T}, shape)
end
T = isleaftype(S) ? S : Any
return _broadcast_t(f, T, shape, iter, As...)
return _broadcast_t(f, Any, shape, iter, As...)
end
function broadcast_c(f, ::Type{Tuple}, As...)
shape = broadcast_indices(As...)
Expand Down

0 comments on commit 5d4cd87

Please sign in to comment.