mirror of
https://github.com/github/codeql.git
synced 2026-04-28 18:25:24 +02:00
Merge pull request #2341 from aschackmull/java/cached-tostring-perf-fixes
Java: Fix a number of performance issues when toString is cached.
This commit is contained in:
@@ -39,6 +39,9 @@ predicate notDeliberatelyBoxed(LocalBoxedVar v) {
|
||||
)
|
||||
}
|
||||
|
||||
pragma[nomagic]
|
||||
int callableGetNumberOfParameters(Callable c) { result = c.getNumberOfParameters() }
|
||||
|
||||
/**
|
||||
* Replacing the type of a boxed variable with the corresponding primitive type may affect
|
||||
* overload resolution. If this is the case then the boxing is most likely intentional and
|
||||
@@ -52,7 +55,7 @@ predicate affectsOverload(LocalBoxedVar v) {
|
||||
c1.getParameterType(i) instanceof RefType and
|
||||
c2.getParameterType(i) instanceof PrimitiveType and
|
||||
c1.getName() = c2.getName() and
|
||||
c1.getNumberOfParameters() = c2.getNumberOfParameters()
|
||||
callableGetNumberOfParameters(c1) = callableGetNumberOfParameters(c2)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -84,6 +84,7 @@ class Top extends @top {
|
||||
int getNumberOfCommentLines() { numlines(this, _, _, result) }
|
||||
|
||||
/** Gets a textual representation of this element. */
|
||||
cached
|
||||
string toString() { hasName(this, result) }
|
||||
}
|
||||
|
||||
|
||||
@@ -301,7 +301,7 @@ class RootdefCallable extends Callable {
|
||||
}
|
||||
}
|
||||
|
||||
pragma[noinline]
|
||||
pragma[nomagic]
|
||||
private predicate overrideAccess(Callable c, int i) {
|
||||
exists(Method m | m.overridesOrInstantiates+(c) | exists(m.getParameter(i).getAnAccess()))
|
||||
}
|
||||
|
||||
@@ -61,19 +61,29 @@ class ClientSideGwtCompilationUnit extends GwtCompilationUnit {
|
||||
}
|
||||
}
|
||||
|
||||
/** Auxiliary predicate: `jsni` is a JSNI comment associated with method `m`. */
|
||||
private predicate jsniComment(Javadoc jsni, Method m) {
|
||||
private predicate jsni(Javadoc jsni, File file, int startline) {
|
||||
// The comment must start with `-{` ...
|
||||
jsni.getChild(0).getText().matches("-{%") and
|
||||
// ... and it must end with `}-`.
|
||||
jsni.getChild(jsni.getNumChild() - 1).getText().matches("%}-") and
|
||||
// The associated callable must be marked as `native` ...
|
||||
file = jsni.getFile() and
|
||||
startline = jsni.getLocation().getStartLine()
|
||||
}
|
||||
|
||||
private predicate nativeMethodLines(Method m, File file, int line) {
|
||||
m.isNative() and
|
||||
// ... and the comment has to be contained in `m`.
|
||||
jsni.getFile() = m.getFile() and
|
||||
jsni.getLocation().getStartLine() in [m.getLocation().getStartLine() .. m
|
||||
.getLocation()
|
||||
.getEndLine()]
|
||||
file = m.getFile() and
|
||||
line in [m.getLocation().getStartLine() .. m.getLocation().getEndLine()]
|
||||
}
|
||||
|
||||
/** Auxiliary predicate: `jsni` is a JSNI comment associated with method `m`. */
|
||||
private predicate jsniComment(Javadoc jsni, Method m) {
|
||||
exists(File file, int line |
|
||||
jsni(jsni, file, line) and
|
||||
// The associated callable must be marked as `native`
|
||||
// and the comment has to be contained in `m`.
|
||||
nativeMethodLines(m, file, line)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user