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 Dec 14, 2017
1 parent a9bb7d3 commit 3d2130e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -758,10 +758,14 @@ Deprecated or removed
in the new `Unicode` standard library module ([#25021]).

* The aliases `Complex32`, `Complex64` and `Complex128` have been deprecated in favor of `ComplexF16`,
`ComplexF32` and `ComplexF64` respectively (#24647).
`ComplexF32` and `ComplexF64` respectively ([#24647]).

* `Associative` has been deprecated in favor of `AbstractDict` ([#25012]).

* `copy!` is deprecated for `AbstractSet` and `AbstractDict`, with the intention to re-enable
it with a cleaner meaning in a future version ([#24844]).

>>>>>>> deprecate copy! for sets and dicts (part of #24808)

This comment has been minimized.

Copy link
@StefanKarpinski

StefanKarpinski Dec 14, 2017

Member

merge artifact left in.

Command-line option changes
---------------------------

Expand Down
9 changes: 0 additions & 9 deletions base/abstractdict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,6 @@ function merge!(combine::Function, d::AbstractDict, others::AbstractDict...)
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{AbstractDict,AbstractSet}, src)
for x in src
push!(dest, x)
end
return dest
end

"""
keytype(type)
Expand Down
7 changes: 6 additions & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,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 these 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
4 changes: 4 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2984,6 +2984,10 @@ end

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

# #24844
@deprecate copy!(dest::AbstractSet, src) union!(dest, src)
@deprecate copy!(dest::AbstractDict, src) foldl(push!, dest, src)

# issue #24019
@deprecate similar(a::AbstractDict) empty(a)
@deprecate similar(a::AbstractDict, ::Type{Pair{K,V}}) where {K, V} empty(a, K, V)
Expand Down
2 changes: 1 addition & 1 deletion base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function grow_to!(dest::AbstractDict{K,V}, itr, st) where V where K
dest[k] = v
else
new = empty(dest, 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 3d2130e

Please sign in to comment.