Skip to content

Commit 9cbe145

Browse files
authored
Add sizehint! to Dict constructor (#35254)
* Add sizehint to Dict constructor * Check iterator has length
1 parent 5420dd2 commit 9cbe145

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

base/dict.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ mutable struct Dict{K,V} <: AbstractDict{K,V}
9999
end
100100
function Dict{K,V}(kv) where V where K
101101
h = Dict{K,V}()
102+
chklen = IteratorSize(kv)
103+
if (chklen isa HasLength) || (chklen isa HasShape)
104+
sizehint!(h, length(kv))
105+
end
102106
for (k,v) in kv
103107
h[k] = v
104108
end

0 commit comments

Comments
 (0)