Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ab6628d

Browse files
Sacha0KristofferC
authored andcommittedNov 11, 2021
Optimize show(io::IO, m::Module) implementation. (#42773)
show(io::IO, m::Module) allocates. This commit provides an implementation that does not allocate, improving perf. (cherry picked from commit ca6b3ba)
1 parent 7b19f16 commit ab6628d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed
 

‎base/show.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,20 @@ function show(io::IO, m::Module)
10111011
if is_root_module(m)
10121012
print(io, nameof(m))
10131013
else
1014-
print(io, join(fullname(m),"."))
1014+
print_fullname(io, m)
1015+
end
1016+
end
1017+
# The call to print_fullname above was originally `print(io, join(fullname(m),"."))`,
1018+
# which allocates. The method below provides the same behavior without allocating.
1019+
# See https://github.com/JuliaLang/julia/pull/42773 for perf information.
1020+
function print_fullname(io::IO, m::Module)
1021+
mp = parentmodule(m)
1022+
if m === Main || m === Base || m === Core || mp === m
1023+
print(io, nameof(m))
1024+
else
1025+
print_fullname(io, mp)
1026+
print(io, '.')
1027+
print(io, nameof(m))
10151028
end
10161029
end
10171030

0 commit comments

Comments
 (0)
Please sign in to comment.