Skip to content

Commit 32122e8

Browse files
committed
C++: use plain recursion in PrimitiveBasicBlocks
It's sometimes faster but sometimes up to 2x slower to use plain recursion here. On the other hand, plain recursion won't run out of Java heap space, and it won't make unrelated computation slower by forcing all RAM data out to disk.
1 parent 16b1517 commit 32122e8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

cpp/ql/src/semmle/code/cpp/controlflow/internal/PrimitiveBasicBlocks.qll

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,14 @@ private cached module Cached {
6262

6363
/** Holds if `node` is the `pos`th control-flow node in primitive basic block `bb`. */
6464
cached
65-
predicate primitive_basic_block_member(Node node, PrimitiveBasicBlock bb, int pos) =
66-
shortestDistances(primitive_basic_block_entry_node/1, member_step/2)(bb, node, pos)
65+
predicate primitive_basic_block_member(Node node, PrimitiveBasicBlock bb, int pos) {
66+
primitive_basic_block_entry_node(bb) and node = bb and pos = 0
67+
or
68+
exists(Node prev |
69+
member_step(prev, node) and
70+
primitive_basic_block_member(prev, bb, pos - 1)
71+
)
72+
}
6773

6874
/** Gets the number of control-flow nodes in the primitive basic block `bb`. */
6975
cached

0 commit comments

Comments
 (0)