Skip to content

Commit

Permalink
deprecate copy! for sets and dicts (part of #24808)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfourquet committed Nov 29, 2017
1 parent 710a3d8 commit b9b7350
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
7 changes: 6 additions & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,12 @@ function grow_to!(dest, itr, st)
push!(dest, el::T)
else
new = similar(dest, typejoin(T, S))
copy!(new, dest)
if new isa AbstractSet
# TODO: merge back those two branches when copy! is re-enabled for sets
union!(new, dest)
else
copy!(new, dest)
end
push!(new, el)
return grow_to!(new, itr, st)
end
Expand Down
9 changes: 0 additions & 9 deletions base/associative.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,6 @@ function merge!(combine::Function, d::Associative, others::Associative...)
return d
end

# very similar to `merge!`, but accepts any iterable and extends code
# that would otherwise only use `copy!` with arrays.
function copy!(dest::Union{Associative,AbstractSet}, src)
for x in src
push!(dest, x)
end
return dest
end

"""
keytype(type)
Expand Down
3 changes: 3 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2150,6 +2150,9 @@ end

@deprecate merge!(repo::LibGit2.GitRepo, args...; kwargs...) LibGit2.merge!(repo, args...; kwargs...)

@deprecate copy!(dest::AbstractSet, src) union!(dest, src)
@deprecate copy!(dest::Associative, src) foldl(push!, dest, src)

# END 0.7 deprecations

# BEGIN 1.0 deprecations
Expand Down
2 changes: 1 addition & 1 deletion base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function grow_to!(dest::Associative{K,V}, itr, st) where V where K
dest[k] = v
else
new = similar(dest, Pair{typejoin(K,typeof(k)), typejoin(V,typeof(v))})
copy!(new, dest)
merge!(new, dest)
new[k] = v
return grow_to!(new, itr, st)
end
Expand Down

0 comments on commit b9b7350

Please sign in to comment.