Skip to content

Commit 01242b2

Browse files
committed
[GR-11592] WhileNode should use counting profile.
1 parent 0fe6726 commit 01242b2

File tree

1 file changed

+8
-5
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/control

1 file changed

+8
-5
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/control/WhileNode.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,27 @@
3333
import com.oracle.truffle.api.nodes.Node;
3434
import com.oracle.truffle.api.nodes.NodeInfo;
3535
import com.oracle.truffle.api.nodes.RepeatingNode;
36+
import com.oracle.truffle.api.profiles.LoopConditionProfile;
3637

3738
final class WhileRepeatingNode extends Node implements RepeatingNode {
3839

40+
private final LoopConditionProfile conditionProfile = LoopConditionProfile.createCountingProfile();
41+
3942
@Child CastToBooleanNode condition;
4043
@Child PNode body;
41-
44+
4245
WhileRepeatingNode(CastToBooleanNode condition, PNode body) {
4346
this.condition = condition;
4447
this.body = body;
4548
}
4649

4750
@Override
4851
public boolean executeRepeating(VirtualFrame frame) {
49-
if (!condition.executeBoolean(frame)) {
50-
return false;
52+
if (conditionProfile.profile(condition.executeBoolean(frame))) {
53+
body.executeVoid(frame);
54+
return true;
5155
}
52-
body.executeVoid(frame);
53-
return true;
56+
return false;
5457
}
5558
}
5659

0 commit comments

Comments
 (0)