Skip to content

Commit

Permalink
speed up is_exported_from_stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Sep 7, 2015
1 parent 47f7b74 commit c2d35bb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ names(m::Module, all::Bool, imported::Bool) = sort!(ccall(:jl_module_names, Arra
names(m::Module, all::Bool) = names(m, all, false)
names(m::Module) = names(m, false, false)

isexported(m::Module, s::Symbol) = ccall(:jl_module_exports_p, Cint, (Any, Any), m, s)!=0

function isbindingresolved(m::Module, var::Symbol)
ccall(:jl_binding_resolved_p, Cint, (Any, Any), m, var) != 0
end
Expand Down
3 changes: 1 addition & 2 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ end

# Check if a particular symbol is exported from a standard library module
function is_exported_from_stdlib(name::Symbol, mod::Module)
if (mod === Base && name in names(Base)) ||
(mod === Core && name in names(Core))
if (mod === Base || mod === Core) && isexported(mod, name)
return true
end
parent = module_parent(mod)
Expand Down
7 changes: 7 additions & 0 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,13 @@ int jl_defines_or_exports_p(jl_module_t *m, jl_sym_t *var)
return (*bp)->exportp || (*bp)->owner==m;
}

DLLEXPORT int jl_module_exports_p(jl_module_t *m, jl_sym_t *var)
{
jl_binding_t **bp = (jl_binding_t**)ptrhash_bp(&m->bindings, var);
if (*bp == HT_NOTFOUND) return 0;
return (*bp)->exportp;
}

int jl_binding_resolved_p(jl_module_t *m, jl_sym_t *var)
{
jl_binding_t **bp = (jl_binding_t**)ptrhash_bp(&m->bindings, var);
Expand Down

0 comments on commit c2d35bb

Please sign in to comment.