|
function find_type(typepath::String) |
|
parts = split(typepath, '.') |
|
# Find a type in the loaded modules by traversing the parts |
|
for mod in Base.loaded_modules_array() |
|
for part in parts |
|
sym = Symbol(part) |
|
(!isa(mod, Module) || !isdefined(mod, sym)) && break |
|
mod = getfield(mod, sym) |
|
end |
|
if mod isa DataType || mod isa UnionAll |
|
# We found a type, so we can stop searching |
|
return mod |
|
end |
|
end |
|
return nothing |
|
end |
Every call to find_type calls Base.loaded_modules_array, which 1) globally locks and 2) creates a fresh copy of the array.
Perhaps JLD2 could look up the loaded_modules_array just once on each loading call and carry that forward? (Is this a use case for ScopedValue?)
JLD2.jl/src/data/reconstructing_datatypes.jl
Lines 324 to 339 in d144466
Every call to
find_typecallsBase.loaded_modules_array, which 1) globally locks and 2) creates a fresh copy of the array.Perhaps JLD2 could look up the
loaded_modules_arrayjust once on each loading call and carry that forward? (Is this a use case for ScopedValue?)