|
1 | 1 | function methods_with(@nospecialize(T::Type), world::UInt = Base.get_world_counter())
|
2 | 2 | meths = Set{Method}()
|
3 |
| - visited = Set{Module}() |
4 |
| - for mod in Base.loaded_modules_array() |
5 |
| - methods_with!(meths, T, world, mod, visited) |
6 |
| - end |
7 |
| - # Also handle the methods defined for Type |
8 |
| - mt = methods(Type).mt |
9 | 3 | T = Base.unwrap_unionall(T)
|
10 | 4 | Tname = T.name
|
11 |
| - for method in Base.MethodList(mt) |
12 |
| - method.module === Tname.module && method.name === Tname.name && continue # skip constructor |
13 |
| - hastype(method.sig, T) && push!(meths, method) |
14 |
| - end |
15 |
| - return meths |
16 |
| -end |
17 |
| - |
18 |
| -function methods_with!(meths, @nospecialize(T::Type), world, mod::Module, visited::Set{Module}) |
19 |
| - mod in visited && return |
20 |
| - push!(visited, mod) |
21 |
| - # Traverse submodules |
22 |
| - for name in names(mod; all=true, imported=false) |
23 |
| - isdefined(mod, name) || continue |
24 |
| - obj = getglobal(mod, name) |
25 |
| - if isa(obj, Module) |
26 |
| - methods_with!(meths, T, world, obj, visited) |
27 |
| - end |
28 |
| - end |
29 |
| - Base.foreach_module_mtable(mod, world) do mt::Core.MethodTable |
30 |
| - for method in Base.MethodList(mt) |
| 5 | + Base.visit(Core.GlobalMethods) do method |
| 6 | + if method.module !== Tname.module || method.name !== Tname.name # skip constructor |
31 | 7 | hastype(method.sig, T) && push!(meths, method)
|
32 | 8 | end
|
33 |
| - return true |
34 | 9 | end
|
35 | 10 | return meths
|
36 | 11 | end
|
|
0 commit comments