Skip to content

Commit 775214e

Browse files
committed
Python speed up calculation of ControlFlowNode.getAChild()
1 parent fad37bd commit 775214e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

python/ql/src/semmle/python/Flow.qll

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,13 +401,18 @@ class ControlFlowNode extends @py_flow_node {
401401
py_true_successors(this, _) or py_false_successors(this, _)
402402
}
403403

404-
/* Gets a CFG node that corresponds to a child of the AST node for this node */
405-
pragma [noinline]
406404
ControlFlowNode getAChild() {
407-
this.getNode().getAChildNode() = result.getNode() and
405+
result = this.getExprChild() and
408406
result.getBasicBlock().dominates(this.getBasicBlock())
409407
}
410408

409+
/* join-ordering helper for `getAChild() */
410+
pragma [noinline]
411+
private ControlFlowNode getExprChild() {
412+
this.getNode().(Expr).getAChildNode() = result.getNode() and
413+
not this instanceof UnaryExprNode
414+
}
415+
411416
}
412417

413418

@@ -1058,7 +1063,7 @@ class BasicBlock extends @py_flow_node {
10581063
this.strictlyDominates(other)
10591064
}
10601065

1061-
BasicBlock getImmediateDominator() {
1066+
cached BasicBlock getImmediateDominator() {
10621067
this.getAPart().getImmediateDominator() = result.getAPart()
10631068
}
10641069

0 commit comments

Comments
 (0)