Skip to content

Commit

Permalink
Optimize show(io::IO, m::Module) implementation. (JuliaLang#42773)
Browse files Browse the repository at this point in the history
show(io::IO, m::Module) allocates. This commit provides
an implementation that does not allocate, improving perf.
  • Loading branch information
Sacha0 authored and LilithHafner committed Feb 22, 2022
1 parent 1144253 commit 128ceca
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,20 @@ function show(io::IO, m::Module)
if is_root_module(m)
print(io, nameof(m))
else
print(io, join(fullname(m),"."))
print_fullname(io, m)
end
end
# The call to print_fullname above was originally `print(io, join(fullname(m),"."))`,
# which allocates. The method below provides the same behavior without allocating.
# See https://github.com/JuliaLang/julia/pull/42773 for perf information.
function print_fullname(io::IO, m::Module)
mp = parentmodule(m)
if m === Main || m === Base || m === Core || mp === m
print(io, nameof(m))
else
print_fullname(io, mp)
print(io, '.')
print(io, nameof(m))
end
end

Expand Down

0 comments on commit 128ceca

Please sign in to comment.