Skip to content

Commit 40d1439

Browse files
committed
Prevent allocs for FD{Int128} by freeze max_exp10
Before this commit, reinterpret(FD{Int128,f}, x) allocates because: 1. max_exp10(Int128) widens the Int128 to a BigInt, which causes allocations. 2. The result of max_exp10(Int128) isn't getting const-folded away, so the above widen operation occurs every time it's called at runtime. This commit simply "freezes" the result for Int128s via a top-level `@eval` statement.
1 parent 1768c58 commit 40d1439

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/FixedPointDecimals.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ function max_exp10(::Type{T}) where {T <: Integer}
484484
end
485485

486486
max_exp10(::Type{BigInt}) = -1
487+
@eval max_exp10(::Type{Int128}) = $(max_exp10(Int128)) # Freeze this, since it's not getting Const folded.
487488

488489
"""
489490
coefficient(::Type{FD{T, f}}) -> T

0 commit comments

Comments
 (0)