Skip to content

Commit 61a196d

Browse files
authored
Merge pull request #1523 from markshannon/python-speed-up-get-a-child
Python speed up calculation of ControlFlowNode.getAChild()
2 parents 8130342 + 775214e commit 61a196d

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

@@ -1066,7 +1071,7 @@ class BasicBlock extends @py_flow_node {
10661071
this.strictlyDominates(other)
10671072
}
10681073

1069-
BasicBlock getImmediateDominator() {
1074+
cached BasicBlock getImmediateDominator() {
10701075
this.getAPart().getImmediateDominator() = result.getAPart()
10711076
}
10721077

0 commit comments

Comments
 (0)