C++: Compute locations only for elements in result

This gains some performance by not computing locations for all
expressions since we are only interested in calls and variable accesses.
The `Top::hasLocationInfo` predicate goes from 2m28s to 1m32s on
Chromium.
This commit is contained in:
Jonas Jensen
2019-05-22 15:44:54 +01:00
parent 81f627c1c4
commit dd5a2552c7

View File

@@ -30,7 +30,7 @@ class Top extends Element {
predicate hasLocationInfo(string filepath,
int startline, int startcolumn,
int endline, int endcolumn) {
this instanceof Element and
interestingElement(this) and
not this instanceof MacroAccess and
not this instanceof Include and
exists(Location l |
@@ -76,6 +76,13 @@ predicate hasLocationInfo_Include(Include i, string path, int sl, int sc, int el
)
}
/** Holds if `e` is a source or a target of jump-to-definition. */
predicate interestingElement(Element e) {
exists(definitionOf(e, _))
or
e = definitionOf(_, _)
}
/**
* Holds if `f`, `line`, `column` indicate the start character
* of `cc`.