Skip to content

Commit 3471e75

Browse files
committed
Ruby: Fix performance problem in Definitions.ql
1 parent 55ea715 commit 3471e75

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,19 @@ newtype DefLoc =
6565
not exists(MethodBase m | m.getAChild+() = write)
6666
}
6767

68+
pragma[noinline]
69+
ConstantWriteAccess definitionOf0(string fqn) {
70+
fqn = resolveConstant(_) and
71+
result =
72+
min(ConstantWriteAccess w | w.getQualifiedName() = fqn | w order by w.getLocation().toString())
73+
}
74+
6875
/**
6976
* Gets the constant write that defines the given constant.
7077
* Modules often don't have a unique definition, as they are opened multiple times in different
7178
* files. In these cases we arbitrarily pick the definition with the lexicographically least
7279
* location.
7380
*/
7481
ConstantWriteAccess definitionOf(ConstantReadAccess r) {
75-
result =
76-
min(ConstantWriteAccess w |
77-
w.getQualifiedName() = resolveConstant(r)
78-
|
79-
w order by w.getLocation().toString()
80-
)
82+
result = definitionOf0(resolveConstant(r))
8183
}

0 commit comments

Comments
 (0)