Skip to content

Commit f6aa09f

Browse files
Sacha0LilithHafner
authored andcommitted
Optimize show(io::IO, m::Module) implementation. (JuliaLang#42773)
show(io::IO, m::Module) allocates. This commit provides an implementation that does not allocate, improving perf.
1 parent fbcbbf3 commit f6aa09f

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
@@ -1096,7 +1096,20 @@ function show(io::IO, m::Module)
10961096
if is_root_module(m)
10971097
print(io, nameof(m))
10981098
else
1099-
print(io, join(fullname(m),"."))
1099+
print_fullname(io, m)
1100+
end
1101+
end
1102+
# The call to print_fullname above was originally `print(io, join(fullname(m),"."))`,
1103+
# which allocates. The method below provides the same behavior without allocating.
1104+
# See https://github.com/JuliaLang/julia/pull/42773 for perf information.
1105+
function print_fullname(io::IO, m::Module)
1106+
mp = parentmodule(m)
1107+
if m === Main || m === Base || m === Core || mp === m
1108+
print(io, nameof(m))
1109+
else
1110+
print_fullname(io, mp)
1111+
print(io, '.')
1112+
print(io, nameof(m))
11001113
end
11011114
end
11021115

0 commit comments

Comments
 (0)