|
433 | 433 | # TODO: use copy!, which is currently unavailable from here since it is defined in Future
|
434 | 434 | _copy_oftype(x, ::Type{T}) where {T} = copyto!(similar(x, T), x)
|
435 | 435 | # TODO: use similar() once deprecation is removed and it preserves keys
|
436 |
| -_copy_oftype(x::AbstractDict, ::Type{T}) where {T} = merge!(empty(x, T), x) |
| 436 | +_copy_oftype(x::AbstractDict, ::Type{Pair{K,V}}) where {K,V} = merge!(empty(x, K, V), x) |
437 | 437 | _copy_oftype(x::AbstractSet, ::Type{T}) where {T} = union!(empty(x, T), x)
|
438 | 438 |
|
439 | 439 | _copy_oftype(x::AbstractArray{T}, ::Type{T}) where {T} = copy(x)
|
@@ -617,8 +617,10 @@ replace(a::AbstractString, b::Pair, c::Pair) = throw(MethodError(replace, (a, b,
|
617 | 617 | askey(k, ::AbstractDict) = k.first
|
618 | 618 | askey(k, ::AbstractSet) = k
|
619 | 619 |
|
620 |
| -function _replace!(new::Callable, res::T, A::T, |
621 |
| - count::Int) where T<:Union{AbstractDict,AbstractSet} |
| 620 | +function _replace!(new::Callable, res::Union{AbstractDict,AbstractSet}, |
| 621 | + A::Union{AbstractDict,AbstractSet}, count::Int) |
| 622 | + @assert res isa AbstractDict && A isa AbstractDict || |
| 623 | + res isa AbstractSet && A isa AbstractSet |
622 | 624 | count == 0 && return res
|
623 | 625 | c = 0
|
624 | 626 | if res === A # cannot replace elements while iterating over A
|
|
686 | 688 |
|
687 | 689 | ### specialization for Dict / Set
|
688 | 690 |
|
689 |
| -function _replace!(new::Callable, t::Dict{K,V}, A::Dict{K,V}, count::Int) where {K,V} |
| 691 | +function _replace!(new::Callable, t::Dict{K,V}, A::AbstractDict, count::Int) where {K,V} |
690 | 692 | # we ignore A, which is supposed to be equal to the destination t,
|
691 | 693 | # as it can generally be faster to just replace inline
|
692 | 694 | count == 0 && return t
|
@@ -718,7 +720,7 @@ function _replace!(new::Callable, t::Dict{K,V}, A::Dict{K,V}, count::Int) where
|
718 | 720 | t
|
719 | 721 | end
|
720 | 722 |
|
721 |
| -function _replace!(new::Callable, t::Set{T}, ::Set{T}, count::Int) where {T} |
| 723 | +function _replace!(new::Callable, t::Set{T}, ::AbstractSet, count::Int) where {T} |
722 | 724 | _replace!(t.dict, t.dict, count) do kv
|
723 | 725 | k = first(kv)
|
724 | 726 | k2 = new(k)
|
|
0 commit comments