Skip to content

Commit db4e82e

Browse files
authored
Merge pull request github#13301 from atorralba/atorralba/java/stub-generator-perf-fix
Java: Fix performance issue in the stub generator
2 parents 4a8320f + 6386ef3 commit db4e82e

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

java/ql/src/utils/stub-generator/Stubs.qll

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,25 @@ private string stubQualifier(RefType t) {
285285
else result = ""
286286
}
287287

288+
pragma[nomagic]
289+
private predicate needsPackageNameHelper(RefType t, GeneratedTopLevel top, string name) {
290+
t.getSourceDeclaration() =
291+
pragma[only_bind_out]([getAReferencedType(top), top].getSourceDeclaration()) and
292+
name = t.getName()
293+
}
294+
295+
pragma[nomagic]
296+
private predicate describesMultipleTypes(GeneratedTopLevel top, string name) {
297+
2 <= strictcount(RefType t | needsPackageNameHelper(t, top, name))
298+
}
299+
288300
/**
289301
* Holds if `t` may clash with another type of the same name, so should be referred to using the fully qualified name
290302
*/
291303
private predicate needsPackageName(RefType t) {
292-
exists(GeneratedTopLevel top, RefType other |
293-
t.getSourceDeclaration() = [getAReferencedType(top), top].getSourceDeclaration() and
294-
other.getSourceDeclaration() = [getAReferencedType(top), top].getSourceDeclaration() and
295-
t.getName() = other.getName() and
296-
t != other
304+
exists(GeneratedTopLevel top, string name |
305+
needsPackageNameHelper(t, top, name) and
306+
describesMultipleTypes(top, name)
297307
)
298308
}
299309

0 commit comments

Comments
 (0)