Skip to content

Commit d1979e3

Browse files
KristofferCJeffBezanson
authored andcommitted
improve performance of setindex! on IdDict (#33009)
1 parent 6821437 commit d1979e3

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

base/abstractdict.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,9 @@ end
579579

580580
function setindex!(d::IdDict{K,V}, @nospecialize(val), @nospecialize(key)) where {K, V}
581581
!isa(key, K) && throw(ArgumentError("$(limitrepr(key)) is not a valid key for type $K"))
582-
val = convert(V, val)
582+
if !(val isa V) # avoid a dynamic call
583+
val = convert(V, val)
584+
end
583585
if d.ndel >= ((3*length(d.ht))>>2)
584586
rehash!(d, max(length(d.ht)>>1, 32))
585587
d.ndel = 0

0 commit comments

Comments
 (0)