Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid unnecessary Docs.META initializations #48469

Merged
merged 1 commit into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ const modules = Module[]
const META = gensym(:meta)
const METAType = IdDict{Any,Any}

function meta(m::Module)
function meta(m::Module; autoinit::Bool=true)
if !isdefined(m, META) || getfield(m, META) === nothing
initmeta(m)
autoinit ? initmeta(m) : return nothing
end
return getfield(m, META)::METAType
end
Expand Down Expand Up @@ -161,7 +161,8 @@ end
function docstr(binding::Binding, typesig = Union{})
@nospecialize typesig
for m in modules
dict = meta(m)
dict = meta(m; autoinit=false)
isnothing(dict) && continue
if haskey(dict, binding)
docs = dict[binding].docs
if haskey(docs, typesig)
Expand Down
10 changes: 7 additions & 3 deletions stdlib/REPL/src/docview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ function doc(binding::Binding, sig::Type = Union{})
results, groups = DocStr[], MultiDoc[]
# Lookup `binding` and `sig` for matches in all modules of the docsystem.
for mod in modules
dict = meta(mod)
dict = meta(mod; autoinit=false)
isnothing(dict) && continue
if haskey(dict, binding)
multidoc = dict[binding]
push!(groups, multidoc)
Expand Down Expand Up @@ -565,7 +566,8 @@ Return documentation for a particular `field` of a type if it exists.
"""
function fielddoc(binding::Binding, field::Symbol)
for mod in modules
dict = meta(mod)
dict = meta(mod; autoinit=false)
isnothing(dict) && continue
if haskey(dict, binding)
multidoc = dict[binding]
if haskey(multidoc.docs, Union{})
Expand Down Expand Up @@ -834,7 +836,9 @@ function apropos(io::IO, needle::Regex)
for mod in modules
# Module doc might be in README.md instead of the META dict
docsearch(doc(mod), needle) && println(io, mod)
for (k, v) in meta(mod)
dict = meta(mod; autoinit=false)
isnothing(dict) && continue
for (k, v) in dict
docsearch(v, needle) && println(io, k)
end
end
Expand Down