Skip to content

Commit d323b3b

Browse files
authored
Merge pull request #7123 from hvitved/ruby/definitions-perf
Ruby: Fix performance problem in `Definitions.ql`
2 parents eef7709 + d1a09b6 commit d323b3b

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

ruby/ql/src/queries/analysis/Definitions.ql

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ select src, target, kind
3535
*/
3636
newtype DefLoc =
3737
/** A constant, module or class. */
38-
ConstantDefLoc(ConstantReadAccess read, ConstantWriteAccess write) { write = definitionOf(read) } or
38+
ConstantDefLoc(ConstantReadAccess read, ConstantWriteAccess write) {
39+
write = definitionOf(resolveConstant(read))
40+
} or
3941
/** A method call. */
4042
MethodLoc(MethodCall call, Method meth) { meth = call.getATarget() } or
4143
/** A local variable. */
@@ -71,11 +73,16 @@ newtype DefLoc =
7173
* files. In these cases we arbitrarily pick the definition with the lexicographically least
7274
* location.
7375
*/
74-
ConstantWriteAccess definitionOf(ConstantReadAccess r) {
76+
pragma[noinline]
77+
ConstantWriteAccess definitionOf(string fqn) {
78+
fqn = resolveConstant(_) and
7579
result =
76-
min(ConstantWriteAccess w |
77-
w.getQualifiedName() = resolveConstant(r)
80+
min(ConstantWriteAccess w, Location l |
81+
w.getQualifiedName() = fqn and l = w.getLocation()
7882
|
79-
w order by w.getLocation().toString()
83+
w
84+
order by
85+
l.getFile().getAbsolutePath(), l.getStartLine(), l.getStartColumn(), l.getEndLine(),
86+
l.getEndColumn()
8087
)
8188
}

0 commit comments

Comments
 (0)