Skip to content

Commit c4ee1fa

Browse files
authored
restore performance of hash for BigInt and Rational{BigInt} (#40881)
When the code was moved out of hashing2.jl, some imports where missed, cancelling the benefits of #33790.
1 parent d93a1c8 commit c4ee1fa

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

base/gmp.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import .Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, (~), (&), (|), xor,
1010
sum, trailing_zeros, trailing_ones, count_ones, tryparse_internal,
1111
bin, oct, dec, hex, isequal, invmod, _prevpow2, _nextpow2, ndigits0zpb,
1212
widen, signed, unsafe_trunc, trunc, iszero, isone, big, flipsign, signbit,
13-
sign, hastypemax, isodd, iseven, digits!
13+
sign, hastypemax, isodd, iseven, digits!, hash, hash_integer
1414

1515
if Clong == Int32
1616
const ClongMax = Union{Int8, Int16, Int32}
@@ -769,8 +769,11 @@ end
769769

770770
if Limb === UInt
771771
# this condition is true most (all?) of the time, and in this case we can define
772-
# an optimized version of the above hash_integer(::Integer, ::UInt) method for BigInt
773-
# used e.g. for Rational{BigInt}
772+
# an optimized version for BigInt of hash_integer (used e.g. for Rational{BigInt}),
773+
# and of hash
774+
775+
using .Base: hash_uint
776+
774777
function hash_integer(n::BigInt, h::UInt)
775778
GC.@preserve n begin
776779
s = n.size
@@ -800,7 +803,7 @@ if Limb === UInt
800803
limb <= typemin(Int) % UInt && return hash(-(limb % Int), h)
801804
end
802805
pow = trailing_zeros(x)
803-
nd = ndigits0z(x, 2)
806+
nd = Base.ndigits0z(x, 2)
804807
idx = _divLimb(pow) + 1
805808
shift = _modLimb(pow) % UInt
806809
upshift = BITS_PER_LIMB - shift

0 commit comments

Comments
 (0)