Skip to content

Commit

Permalink
Allow faster merge for Dicts (#22737)
Browse files Browse the repository at this point in the history
  • Loading branch information
garborg authored and KristofferC committed Oct 1, 2017
1 parent 75bf562 commit e88b264
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions base/associative.jl
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ Dict{String,Float64} with 3 entries:
```
"""
merge(d::Associative, others::Associative...) =
merge!(emptymergedict(d, others...), d, others...)
merge!(_typeddict(d, others...), others...)

"""
merge(combine, d::Associative, others::Associative...)
Expand Down Expand Up @@ -316,16 +316,16 @@ Dict{String,Float64} with 3 entries:
```
"""
merge(combine::Function, d::Associative, others::Associative...) =
merge!(combine, emptymergedict(d, others...), d, others...)
merge!(combine, _typeddict(d, others...), others...)

promoteK(K) = K
promoteV(V) = V
promoteK(K, d, ds...) = promoteK(promote_type(K, keytype(d)), ds...)
promoteV(V, d, ds...) = promoteV(promote_type(V, valtype(d)), ds...)
function emptymergedict(d::Associative, others::Associative...)
function _typeddict(d::Associative, others::Associative...)
K = promoteK(keytype(d), others...)
V = promoteV(valtype(d), others...)
Dict{K,V}()
Dict{K,V}(d)
end

"""
Expand Down

0 comments on commit e88b264

Please sign in to comment.