diff --git a/base/dict.jl b/base/dict.jl index 2d4b24075381f..cc5c9efb6ada8 100644 --- a/base/dict.jl +++ b/base/dict.jl @@ -231,15 +231,16 @@ end function sizehint!(d::Dict{T}, newsz) where T oldsz = length(d.slots) + # limit new element count to max_values of the key type + newsz = min(newsz, max_values(T)::Int) + # need at least 1.5n space to hold n elements + newsz = cld(3 * newsz, 2) if newsz <= oldsz # todo: shrink # be careful: rehash!() assumes everything fits. it was only designed # for growing. return d end - # grow at least 25% - newsz = min(max(newsz, (oldsz*5)>>2), - max_values(T)::Int) rehash!(d, newsz) end