Skip to content

Commit

Permalink
Minor improvements of _tablesz implementation (#39126)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
bkamins and KristofferC committed May 17, 2022
1 parent 4605704 commit 7bff5cd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion base/abstractdict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}}

Expand Down

0 comments on commit 7bff5cd

Please sign in to comment.