Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix performance of broadcast and collect with Union{T, Missing} #30480

Merged
merged 1 commit into from
Jan 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member Author

@nalimilan nalimilan Dec 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether typeof(val) === T is needed is not clear (#30125), but I've added it for consistency with collect_to!. If that's redundant, we should remove all uses at the same time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we should remove that from everywhere

@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