Skip to content

Commit deba118

Browse files
authored
Base.MPFR: avoid reading the global defaults unless necessary (#56095)
Another follow-up to #51362. Make sure the global default precision and rounding mode are only dereferenced when necessary (when there's no relevant scope, in the ScopedValues sense). Currently this change doesn't result in performance improvements, presumably due to how costly the access to a `ScopedValue` currently is, but the idea is to avoid the cost of the dereference when possible. Once ScopedValues are better optimized by the compiler, I guess this would also result in better effects in case it's known that a call is within a ScopedValues scope.
1 parent 2a89f71 commit deba118

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

base/mpfr.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ Base.copyto!(fd::BigFloatData, limbs) = copyto!(getfield(fd, :d), offset_p_limbs
243243

244244
include("rawbigfloats.jl")
245245

246-
rounding_raw(::Type{BigFloat}) = something(Base.ScopedValues.get(CURRENT_ROUNDING_MODE), ROUNDING_MODE[])
246+
rounding_raw(::Type{BigFloat}) = @something(Base.ScopedValues.get(CURRENT_ROUNDING_MODE), ROUNDING_MODE[])
247247
setrounding_raw(::Type{BigFloat}, r::MPFRRoundingMode) = ROUNDING_MODE[]=r
248248
function setrounding_raw(f::Function, ::Type{BigFloat}, r::MPFRRoundingMode)
249249
Base.ScopedValues.@with(CURRENT_ROUNDING_MODE => r, f())
@@ -1044,7 +1044,7 @@ _convert_precision_from_base(precision::Integer, base::Integer) =
10441044
base == 2 ? precision : ceil(Int, precision * log2(base))
10451045

10461046
_precision_with_base_2(::Type{BigFloat}) =
1047-
Int(something(Base.ScopedValues.get(CURRENT_PRECISION), DEFAULT_PRECISION[])) # default precision of the type BigFloat itself
1047+
Int(@something(Base.ScopedValues.get(CURRENT_PRECISION), DEFAULT_PRECISION[])) # default precision of the type BigFloat itself
10481048

10491049
"""
10501050
setprecision([T=BigFloat,] precision::Int; base=2)

0 commit comments

Comments
 (0)