Skip to content

Commit 67b0ae6

Browse files
committed
FunctoolsModuleBuiltins: reduce, report loop count
1 parent 1351c0f commit 67b0ae6

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/FunctoolsModuleBuiltins.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import static com.oracle.graal.python.nodes.ErrorMessages.S_ARG_MUST_BE_CALLABLE;
4747
import static com.oracle.graal.python.nodes.ErrorMessages.S_ARG_N_MUST_SUPPORT_ITERATION;
4848
import static com.oracle.graal.python.nodes.ErrorMessages.TYPE_S_TAKES_AT_LEAST_ONE_ARGUMENT;
49+
import static com.oracle.truffle.api.nodes.LoopNode.reportLoopCount;
4950

5051
import java.util.List;
5152

@@ -124,6 +125,7 @@ Object doReduce(VirtualFrame frame, Object function, Object sequence, Object ini
124125

125126
Object[] args = new Object[2];
126127

128+
int count = 0;
127129
while (true) {
128130
Object op2;
129131
try {
@@ -136,11 +138,13 @@ Object doReduce(VirtualFrame frame, Object function, Object sequence, Object ini
136138
args[1] = op2;
137139
result = callNode.execute(frame, function, args);
138140
}
141+
count++;
139142
} catch (PException e) {
140143
e.expectStopIteration(stopIterProfile);
141144
break;
142145
}
143146
}
147+
reportLoopCount(this, count);
144148

145149
if (result == null) {
146150
throw raise(PythonBuiltinClassType.TypeError, REDUCE_EMPTY_SEQ);

0 commit comments

Comments
 (0)