From 7bff5cdd0fab8d625e48b3a9bb4e94286f2ba18c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Tue, 17 May 2022 18:35:53 +0200 Subject: [PATCH] Minor improvements of _tablesz implementation (#39126) Probably this does not affect any Julia Base code, but in general the original code was not type stable and safe: Before the PR: ``` julia> Base._tablesz(true) # now it will be an error 16 julia> Base._tablesz(Int32(20)) # now it will be Int32(32) 0 ``` Co-authored-by: Kristoffer Carlsson --- base/abstractdict.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/abstractdict.jl b/base/abstractdict.jl index 527b422fb5684..7f1d8b4a1c504 100644 --- a/base/abstractdict.jl +++ b/base/abstractdict.jl @@ -573,7 +573,7 @@ function convert(::Type{T}, x::AbstractDict) where T<:AbstractDict end # hashing objects by identity -_tablesz(x::Integer) = x < 16 ? 16 : one(x)<<((sizeof(x)<<3)-leading_zeros(x-1)) +_tablesz(x::T) where T <: Integer = x < 16 ? T(16) : one(T)<<((sizeof(T)<<3)-leading_zeros(x-one(T))) TP{K,V} = Union{Type{Tuple{K,V}},Type{Pair{K,V}}}