Skip to content

Commit

Permalink
Fix performance of broadcast and collect with Union{T, Missing}
Browse files Browse the repository at this point in the history
Use the same pattern as in collect_to_with_first! (which is used when size is known).
  • Loading branch information
nalimilan committed Dec 21, 2018
1 parent c8c48a2 commit 184fbc4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
3 changes: 1 addition & 2 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,7 @@ function grow_to!(dest, itr, st)
y = iterate(itr, st)
while y !== nothing
el, st = y
S = typeof(el)
if S === T || S <: T
if el isa T || typeof(el) === T
push!(dest, el::T)
else
new = push_widen(dest, el)
Expand Down
5 changes: 2 additions & 3 deletions base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -926,13 +926,12 @@ function copyto_nonleaf!(dest, bc::Broadcasted, iter, state, count)
y === nothing && break
I, state = y
@inbounds val = bc[I]
S = typeof(val)
if S <: T
if val isa T || typeof(val) === T
@inbounds dest[I] = val
else
# This element type doesn't fit in dest. Allocate a new dest with wider eltype,
# copy over old values, and continue
newdest = Base.similar(dest, promote_typejoin(T, S))
newdest = Base.similar(dest, promote_typejoin(T, typeof(val)))
for II in Iterators.take(iter, count)
newdest[II] = dest[II]
end
Expand Down

0 comments on commit 184fbc4

Please sign in to comment.