From a2373578d3ca79d2660d1296d1d5fafe61ad8843 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Wed, 21 Aug 2019 16:02:42 +0200 Subject: [PATCH 1/2] improve performance of setindex! on IdDict --- base/abstractdict.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/base/abstractdict.jl b/base/abstractdict.jl index cddf03b60c535..7d8d6b2d0c0f7 100644 --- a/base/abstractdict.jl +++ b/base/abstractdict.jl @@ -579,7 +579,9 @@ end function setindex!(d::IdDict{K,V}, @nospecialize(val), @nospecialize(key)) where {K, V} !isa(key, K) && throw(ArgumentError("$(limitrepr(key)) is not a valid key for type $K")) - val = convert(V, val) + if !(val isa V) && V !== Any + val = convert(V, val) + end if d.ndel >= ((3*length(d.ht))>>2) rehash!(d, max(length(d.ht)>>1, 32)) d.ndel = 0 From 2f8d377ab5c0e2f9cfad23d26a9dd0b3eca02ac4 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Wed, 21 Aug 2019 16:23:56 +0200 Subject: [PATCH 2/2] Update abstractdict.jl --- base/abstractdict.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/abstractdict.jl b/base/abstractdict.jl index 7d8d6b2d0c0f7..4e3d568c0a896 100644 --- a/base/abstractdict.jl +++ b/base/abstractdict.jl @@ -579,7 +579,7 @@ end function setindex!(d::IdDict{K,V}, @nospecialize(val), @nospecialize(key)) where {K, V} !isa(key, K) && throw(ArgumentError("$(limitrepr(key)) is not a valid key for type $K")) - if !(val isa V) && V !== Any + if !(val isa V) # avoid a dynamic call val = convert(V, val) end if d.ndel >= ((3*length(d.ht))>>2)