@@ -47,29 +47,28 @@ given signature `sig`. If no applicable methods are found, an empty result is
4747returned. If the number of applicable methods exceeded the specified limit,
4848`missing` is returned.
4949"""
50- function findall (@nospecialize (sig:: Type ), table:: InternalMethodTable ; limit:: Int = typemax (Int ))
50+ function findall (@nospecialize (sig:: Type ), table:: InternalMethodTable ; limit:: Int = Int ( typemax (Int32) ))
5151 return _findall (sig, nothing , table. world, limit)
5252end
5353
54- function findall (@nospecialize (sig:: Type ), table:: OverlayMethodTable ; limit:: Int = typemax (Int ))
54+ function findall (@nospecialize (sig:: Type ), table:: OverlayMethodTable ; limit:: Int = Int ( typemax (Int32) ))
5555 result = _findall (sig, table. mt, table. world, limit)
5656 result === missing && return missing
57- if ! isempty (result)
58- if all (match-> match. fully_covers, result)
59- # no need to fall back to the internal method table
60- return result
61- else
62- # merge the match results with the internal method table
63- fallback_result = _findall (sig, nothing , table. world, limit)
64- return MethodLookupResult (
65- vcat (result. matches, fallback_result. matches),
66- WorldRange (min (result. valid_worlds. min_world, fallback_result. valid_worlds. min_world),
67- max (result. valid_worlds. max_world, fallback_result. valid_worlds. max_world)),
68- result. ambig | fallback_result. ambig)
69- end
57+ nr = length (result)
58+ if nr ≥ 1 && result[nr]. fully_covers
59+ # no need to fall back to the internal method table
60+ return result
7061 end
7162 # fall back to the internal method table
72- return _findall (sig, nothing , table. world, limit)
63+ fallback_result = _findall (sig, nothing , table. world, limit)
64+ fallback_result === missing && return missing
65+ # merge the fallback match results with the internal method table
66+ return MethodLookupResult (
67+ vcat (result. matches, fallback_result. matches),
68+ WorldRange (
69+ max (result. valid_worlds. min_world, fallback_result. valid_worlds. min_world),
70+ min (result. valid_worlds. max_world, fallback_result. valid_worlds. max_world)),
71+ result. ambig | fallback_result. ambig)
7372end
7473
7574function _findall (@nospecialize (sig:: Type ), mt:: Union{Nothing,Core.MethodTable} , world:: UInt , limit:: Int )
@@ -102,17 +101,22 @@ function findsup(@nospecialize(sig::Type), table::InternalMethodTable)
102101end
103102
104103function findsup (@nospecialize (sig:: Type ), table:: OverlayMethodTable )
105- result = _findsup (sig, table. mt, table. world)
106- result === nothing || return result
107- return _findsup (sig, nothing , table. world) # fall back to the internal method table
104+ match, valid_worlds = _findsup (sig, table. mt, table. world)
105+ match != = nothing && return match, valid_worlds
106+ # fall back to the internal method table
107+ fallback_match, fallback_valid_worlds = _findsup (sig, nothing , table. world)
108+ return fallback_match, WorldRange (
109+ max (valid_worlds. min_world, fallback_valid_worlds. min_world),
110+ min (valid_worlds. max_world, fallback_valid_worlds. max_world))
108111end
109112
110113function _findsup (@nospecialize (sig:: Type ), mt:: Union{Nothing,Core.MethodTable} , world:: UInt )
111114 min_valid = RefValue {UInt} (typemin (UInt))
112115 max_valid = RefValue {UInt} (typemax (UInt))
113- result = ccall (:jl_gf_invoke_lookup_worlds , Any, (Any, Any, UInt, Ptr{Csize_t}, Ptr{Csize_t}),
116+ match = ccall (:jl_gf_invoke_lookup_worlds , Any, (Any, Any, UInt, Ptr{Csize_t}, Ptr{Csize_t}),
114117 sig, mt, world, min_valid, max_valid):: Union{MethodMatch, Nothing}
115- return result === nothing ? result : (result, WorldRange (min_valid[], max_valid[]))
118+ valid_worlds = WorldRange (min_valid[], max_valid[])
119+ return match, valid_worlds
116120end
117121
118122isoverlayed (:: MethodTableView ) = error (" unsatisfied MethodTableView interface" )
0 commit comments