Skip to content

Commit d4bca99

Browse files
rfourquetKristofferC
authored andcommitted
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. (cherry picked from commit c4ee1fa)
1 parent ef23162 commit d4bca99

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, digits!
13+
sign, hastypemax, isodd, digits!, hash, hash_integer
1414

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

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

0 commit comments

Comments
 (0)