@@ -31,12 +31,6 @@ const OPTIONS_ROUND_THROWS = Parsers.Options(rounding=nothing)
3131# TODO : a lookup table per type would be faster
3232@inline _shift (n:: T , decpos) where {T} = T (10 )^ decpos * n
3333
34- const _BIGINT1 = BigInt (1 )
35- const _BIGINT2 = BigInt (2 )
36- const _BIGINT10 = BigInt (10 )
37- const _BIGINT_10s = BigInt[] # buffer for "remainders" in _divpow10!, accessed via `Parsers.access_threaded`
38- const _BIGINT_Rs = BigInt[] # buffer for "remainders" in _divpow10!, accessed via `Parsers.access_threaded`
39-
4034for T in (Base. BitSigned_types... , Base. BitUnsigned_types... )
4135 let bytes = Tuple (codeunits (string (typemax (T))))
4236 # The number of digits an integer of type T can hold
@@ -74,8 +68,8 @@ function _divpow10!(x::T, code, pow, ::RoundingMode{:Throw}) where {T}
7468end
7569function _divpow10! (x:: BigInt , code, pow, :: RoundingMode{:Nearest} )
7670 # adapted from https://github.com/JuliaLang/julia/blob/112554e1a533cebad4cb0daa27df59636405c075/base/div.jl#L217
77- @inbounds r = Parsers . access_threaded (() -> ( @static VERSION > v " 1.5 " ? BigInt (; nbits = 256 ) : BigInt ()), _BIGINT_Rs ) # we must not yield here!
78- @inbounds y = Parsers . access_threaded (() -> ( @static VERSION > v " 1.5 " ? BigInt (; nbits = 256 ) : BigInt ()), _BIGINT_10s ) # we must not yield here!
71+ r = _get_bigintRs ( ) # we must not yield here!
72+ y = _get_bigint10s ( ) # we must not yield here!
7973 Base. GMP. MPZ. set! (y, _BIGINT10) # y = 10
8074 Base. GMP. MPZ. pow_ui! (y, pow) # y = y^pow
8175 Base. GMP. MPZ. tdiv_qr! (x, r, x, y) # x, r = divrem(x, y)
@@ -87,15 +81,15 @@ function _divpow10!(x::BigInt, code, pow, ::RoundingMode{:Nearest})
8781 return x, code
8882end
8983function _divpow10! (x:: BigInt , code, pow, :: RoundingMode{:ToZero} )
90- @inbounds y = Parsers . access_threaded (() -> ( @static VERSION > v " 1.5 " ? BigInt (; nbits = 256 ) : BigInt ()), _BIGINT_10s ) # we must not yield here!
84+ y = _get_bigint10s ( ) # we must not yield here!
9185 Base. GMP. MPZ. set! (y, _BIGINT10) # y = 10
9286 Base. GMP. MPZ. pow_ui! (y, pow) # y = y^pow
9387 Base. GMP. MPZ. tdiv_q! (x, y) # x = div(x, y)
9488 return x, code
9589end
9690
9791function _divpow10! (x:: BigInt , code, pow, :: RoundingMode{:Throw} )
98- @inbounds y = Parsers . access_threaded (() -> ( @static VERSION > v " 1.5 " ? BigInt (; nbits = 256 ) : BigInt ()), _BIGINT_10s ) # we must not yield here!
92+ y = _get_bigint10s ( ) # we must not yield here!
9993 Base. GMP. MPZ. set! (y, _BIGINT10) # y = 10
10094 Base. GMP. MPZ. pow_ui! (y, pow) # y = y^pow
10195 Base. GMP. MPZ. tdiv_qr! (x, y, x, y) # x, y = divrem(x, y)
0 commit comments