Skip to content

Commit c3f3628

Browse files
committed
QL: performance improvements
1 parent 0154f4e commit c3f3628

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

ql/src/codeql_ql/ast/Ast.qll

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class AstNode extends TAstNode {
4949
/**
5050
* Gets the parent in the AST for this node.
5151
*/
52+
cached
5253
AstNode getParent() { result.getAChild(_) = this }
5354

5455
/**
@@ -74,12 +75,14 @@ class AstNode extends TAstNode {
7475
predicate hasAnnotation(string name) { this.getAnAnnotation().getName() = name }
7576

7677
/** Gets an annotation of this AST node. */
77-
Annotation getAnAnnotation() { toQL(this).getParent() = toQL(result).getParent() }
78+
Annotation getAnAnnotation() {
79+
toQL(this).getParent() = pragma[only_bind_out](toQL(result)).getParent()
80+
}
7881

7982
/**
8083
* Gets the predicate that contains this AST node.
8184
*/
82-
pragma[noinline]
85+
cached
8386
Predicate getEnclosingPredicate() { this = getANodeInPredicate(result) }
8487
}
8588

@@ -2231,6 +2234,8 @@ class Annotation extends TAnnotation, AstNode {
22312234
/** Gets the node corresponding to the field `name`. */
22322235
string getName() { result = annot.getName().getValue() }
22332236

2237+
override AstNode getParent() { result = AstNode.super.getParent() }
2238+
22342239
override AstNode getAChild(string pred) {
22352240
result = super.getAChild(pred)
22362241
or

ql/src/codeql_ql/ast/internal/AstNodes.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ private QL::AstNode toGenerateYAML(AST::AstNode n) {
126126
/**
127127
* Gets the underlying TreeSitter entity for a given AST node.
128128
*/
129+
cached
129130
QL::AstNode toQL(AST::AstNode n) {
130131
result = toQLExpr(n)
131132
or

0 commit comments

Comments
 (0)