Skip to content

Commit b24971b

Browse files
NodeIntermediateWalker: optimize stack space usage
1 parent 32369f3 commit b24971b

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

keyext.proofmanagement/src/main/java/org/key_project/proofmanagement/check/dependency/NodeIntermediateWalker.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,16 @@ public void start() {
3737
protected void walk(NodeIntermediate node) {
3838
doAction(node);
3939

40-
for (NodeIntermediate child : node.getChildren()) {
40+
// Optimization: for the common case of a single child node,
41+
// avoid recursion (prevents stack overflow for large proof)
42+
var children = node.getChildren();
43+
while (children.size() == 1) {
44+
var nextNode = children.getFirst();
45+
doAction(nextNode);
46+
children = nextNode.getChildren();
47+
}
48+
49+
for (NodeIntermediate child : children) {
4150
walk(child);
4251
}
4352
}

0 commit comments

Comments
 (0)