Skip to content

Commit 9117f64

Browse files
committed
Base.MPFR: avoid reading the global defaults unless necessary
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 30177d0 commit 9117f64

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
@@ -238,7 +238,7 @@ Base.copyto!(fd::BigFloatData, limbs) = copyto!(getfield(fd, :d), offset_p_limbs
238238

239239
include("rawbigfloats.jl")
240240

241-
rounding_raw(::Type{BigFloat}) = something(Base.ScopedValues.get(CURRENT_ROUNDING_MODE), ROUNDING_MODE[])
241+
rounding_raw(::Type{BigFloat}) = @something(Base.ScopedValues.get(CURRENT_ROUNDING_MODE), ROUNDING_MODE[])
242242
setrounding_raw(::Type{BigFloat}, r::MPFRRoundingMode) = ROUNDING_MODE[]=r
243243
function setrounding_raw(f::Function, ::Type{BigFloat}, r::MPFRRoundingMode)
244244
Base.ScopedValues.@with(CURRENT_ROUNDING_MODE => r, f())
@@ -1039,7 +1039,7 @@ _convert_precision_from_base(precision::Integer, base::Integer) =
10391039
base == 2 ? precision : ceil(Int, precision * log2(base))
10401040

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

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

0 commit comments

Comments
 (0)