Skip to content

Commit 953001e

Browse files
committed
Use generated function for showtype
1 parent 83e522a commit 953001e

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/FixedPointNumbers.jl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -466,17 +466,18 @@ function alias_symbol(@nospecialize(X))
466466
Symbol(type_prefix(X), nbitsint(X), 'f', nbitsfrac(X))
467467
end
468468

469+
function _alias_symbol(::Type{X}) where {X <: FixedPoint}
470+
if @generated
471+
sym = string(alias_symbol(X))
472+
return :(Symbol($sym))
473+
else
474+
return alias_symbol(X)
475+
end
476+
end
477+
469478
@inline function showtype(io::IO, ::Type{X}) where {X <: FixedPoint}
470479
if hasalias(X)
471-
# low-level code equivalent to `write(io, alias_symbol(X))`
472-
# This is faster than dynamic string `print`ing, but still slow.
473-
f = nbitsfrac(X)
474-
m = nbitsint(X)
475-
write(io, type_prefix(X))
476-
m > 9 && write(io, (m ÷ 10) % UInt8 + 0x30)
477-
write(io, (m % 10) % UInt8 + 0x30, 0x66)
478-
f > 9 && write(io, (f ÷ 10) % UInt8 + 0x30)
479-
write(io, (f % 10) % UInt8 + 0x30)
480+
write(io, _alias_symbol(X))
480481
else
481482
print(io, X)
482483
end

0 commit comments

Comments
 (0)