fix performance

This commit is contained in:
Erik Krogh Kristensen
2021-10-15 13:31:35 +02:00
parent e185382c41
commit 1a79b13bdc
2 changed files with 13 additions and 8 deletions

View File

@@ -70,7 +70,10 @@ class AstNode extends TAstNode {
predicate hasAnnotation(string name) { this.getAnAnnotation().getName() = name }
/** Gets an annotation of this AST node. */
Annotation getAnAnnotation() { toQL(this).getParent() = toQL(result).getParent() }
cached
Annotation getAnAnnotation() {
toQL(this).getParent() = pragma[only_bind_out](toQL(result)).getParent()
}
/**
* Gets the predicate that contains this AST node.

View File

@@ -148,14 +148,16 @@ private predicate resolveSelectionName(Import imp, ContainerOrModule m, int i) {
cached
private module Cached {
// TODO: Use `AstNode::getParent` once it is total
private QL::AstNode parent(QL::AstNode n) {
result = n.getParent() and
not n instanceof QL::Module
}
private Module getEnclosingModule0(AstNode n) {
AstNodes::toQL(result) = parent*(AstNodes::toQL(n).getParent())
not n instanceof Module and
(
n = result.getAChild(_)
or
exists(AstNode prev |
result = getEnclosingModule0(prev) and
n = prev.getAChild(_)
)
)
}
cached