Skip to content

Commit 0796e5c

Browse files
committed
Use a single signature-dict and switch to LineNumberNode
This reduces the number of lookups, and should therefore be slightly more efficient.
1 parent cea76d4 commit 0796e5c

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/CodeTracking.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ Return the file and line of the definition of `method`. `line`
1717
is the first line of the method's body.
1818
"""
1919
function whereis(method::Method)
20-
lin = get(method_locations, method.sig, nothing)
20+
lin = get(method_info, method.sig, nothing)
2121
if lin === nothing
2222
file, line = String(method.file), method.line
2323
else
24-
file, line = fileline(lin)
24+
file, line = fileline(lin[1])
2525
end
2626
if !isabspath(file)
2727
# This is a Base or Core method
@@ -68,15 +68,15 @@ end
6868
Return an expression that defines `method`.
6969
"""
7070
function definition(method::Method, ::Type{Expr})
71-
def = get(method_definitions, method.sig, nothing)
71+
def = get(method_info, method.sig, nothing)
7272
if def === nothing
7373
f = method_lookup_callback[]
7474
if f !== nothing
7575
Base.invokelatest(f, method)
7676
end
77-
def = get(method_definitions, method.sig, nothing)
77+
def = get(method_info, method.sig, nothing)
7878
end
79-
return def === nothing ? nothing : copy(def)
79+
return def === nothing ? nothing : copy(def[2])
8080
end
8181

8282
definition(method::Method) = definition(method, Expr)

src/data.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ function Base.show(io::IO, info::PkgFiles)
3333
show(io, info.files)
3434
end
3535

36-
const method_locations = IdDict{Type,LineInfoNode}()
37-
38-
const method_definitions = IdDict{Type,Expr}()
36+
const method_info = IdDict{Type,Tuple{LineNumberNode,Expr}}()
3937

4038
const _pkgfiles = Dict{PkgId,PkgFiles}()
4139

src/utils.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ function isfuncexpr(ex)
1313
return false
1414
end
1515

16-
fileline(lin::LineInfoNode) = String(lin.file), lin.line
16+
fileline(lin::LineInfoNode) = String(lin.file), lin.line
17+
fileline(lnn::LineNumberNode) = String(lnn.file), lnn.line
18+
19+
# This is piracy, but it's not ambiguous in terms of what it should do
20+
Base.convert(::Type{LineNumberNode}, lin::LineInfoNode) = LineNumberNode(lin.line, lin.file)
1721

1822
function basepath(id::PkgId)
1923
id.name ("Main", "Base", "Core") && return ""

0 commit comments

Comments
 (0)