Skip to content

Commit d3c3775

Browse files
committed
Use generated function for showtype
1 parent c3304ef commit d3c3775

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
@@ -442,17 +442,18 @@ function alias_symbol(@nospecialize(X))
442442
Symbol(type_prefix(X), nbitsint(X), 'f', nbitsfrac(X))
443443
end
444444

445+
function _alias_symbol(::Type{X}) where {X <: FixedPoint}
446+
if @generated
447+
sym = string(alias_symbol(X))
448+
return :(Symbol($sym))
449+
else
450+
return alias_symbol(X)
451+
end
452+
end
453+
445454
@inline function showtype(io::IO, ::Type{X}) where {X <: FixedPoint}
446455
if hasalias(X)
447-
# low-level code equivalent to `write(io, alias_symbol(X))`
448-
# This is faster than dynamic string `print`ing, but still slow.
449-
f = nbitsfrac(X)
450-
m = nbitsint(X)
451-
write(io, type_prefix(X))
452-
m > 9 && write(io, (m ÷ 10) % UInt8 + 0x30)
453-
write(io, (m % 10) % UInt8 + 0x30, 0x66)
454-
f > 9 && write(io, (f ÷ 10) % UInt8 + 0x30)
455-
write(io, (f % 10) % UInt8 + 0x30)
456+
write(io, _alias_symbol(X))
456457
else
457458
print(io, X)
458459
end

0 commit comments

Comments
 (0)