Skip to content

Commit d658ef1

Browse files
authored
Merge pull request github#6449 from hvitved/python/contains-in-scope-perf
Python: Avoid bad join in `AstExtended::AstNode::containsInScope`
2 parents cb73100 + ea6d51f commit d658ef1

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

python/ql/src/semmle/python/AstExtended.qll

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,15 @@ abstract class AstNode extends AstNode_ {
4949
/** Whether this contains `inner` syntactically */
5050
predicate contains(AstNode inner) { this.getAChildNode+() = inner }
5151

52-
/** Whether this contains `inner` syntactically and `inner` has the same scope as `this` */
53-
predicate containsInScope(AstNode inner) {
52+
pragma[noinline]
53+
private predicate containsInScope(AstNode inner, Scope scope) {
5454
this.contains(inner) and
55-
this.getScope() = inner.getScope() and
56-
not inner instanceof Scope
55+
not inner instanceof Scope and
56+
scope = this.getScope()
5757
}
58+
59+
/** Whether this contains `inner` syntactically and `inner` has the same scope as `this` */
60+
predicate containsInScope(AstNode inner) { this.containsInScope(inner, inner.getScope()) }
5861
}
5962

6063
/* Parents */

0 commit comments

Comments
 (0)