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 743e966
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,9 @@ Deprecated or removed
* `cumsum`, `cumprod`, `accumulate`, and their mutating versions now require a `dim`
argument instead of defaulting to using the first dimension ([#24684]).

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

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

Expand Down
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 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
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 743e966

Please sign in to comment.