Skip to content

Commit 522e6ed

Browse files
committed
Fixed infinite loops + profiling for HashingStorage
Signed-off-by: Octave Larose <[email protected]>
1 parent de15e38 commit 522e6ed

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,8 @@ boolean doBoolSequence(VirtualFrame frame,
317317
BoolSequenceStorage sequenceStorage,
318318
NodeType nodeType) {
319319
boolean[] internalArray = sequenceStorage.getInternalBoolArray();
320-
int i = 0;
321320

322-
while (loopConditionProfile.profile(i < sequenceStorage.length())) {
321+
for (int i = 0; loopConditionProfile.profile(i < sequenceStorage.length()); i++) {
323322
if (nodeType == NodeType.ALL && !isTrueNode.execute(frame, internalArray[i])) {
324323
return false;
325324
} else if (nodeType == NodeType.ANY && isTrueNode.execute(frame, internalArray[i])) {
@@ -336,9 +335,8 @@ boolean doIntSequence(VirtualFrame frame,
336335
IntSequenceStorage sequenceStorage,
337336
NodeType nodeType) {
338337
int[] internalArray = sequenceStorage.getInternalIntArray();
339-
int i = 0;
340338

341-
while (loopConditionProfile.profile(i < sequenceStorage.length())) {
339+
for (int i = 0; loopConditionProfile.profile(i < sequenceStorage.length()); i++) {
342340
if (nodeType == NodeType.ALL && !isTrueNode.execute(frame, internalArray[i])) {
343341
return false;
344342
} else if (nodeType == NodeType.ANY && isTrueNode.execute(frame, internalArray[i])) {
@@ -355,10 +353,9 @@ boolean doGenericSequence(VirtualFrame frame,
355353
NodeType nodeType,
356354
@Cached SequenceStorageNodes.LenNode lenNode) {
357355
Object[] internalArray = sequenceStorage.getInternalArray();
358-
int i = 0;
359356
int seqLength = lenNode.execute(sequenceStorage);
360357

361-
while (loopConditionProfile.profile(i < seqLength)) {
358+
for (int i = 0; loopConditionProfile.profile(i < seqLength); i++) {
362359
if (nodeType == NodeType.ALL && !isTrueNode.execute(frame, internalArray[i])) {
363360
return false;
364361
} else if (nodeType == NodeType.ANY && isTrueNode.execute(frame, internalArray[i])) {
@@ -374,8 +371,10 @@ protected boolean doHashStorage(VirtualFrame frame,
374371
HashingStorage hashingStorage,
375372
NodeType nodeType,
376373
@CachedLibrary("hashingStorage") HashingStorageLibrary hlib) {
377-
for (Object key : hlib.keys(hashingStorage)) {
378-
LoopNode.reportLoopCount(this, 1);
374+
HashingStorageLibrary.HashingStorageIterator<Object> keysIter = hlib.keys(hashingStorage).iterator();
375+
376+
for (int i = 0; loopConditionProfile.profile(i < hlib.length(hashingStorage)); i++) {
377+
Object key = keysIter.next();
379378
if (nodeType == NodeType.ALL) {
380379
if (!isTrueNode.execute(frame, key)) {
381380
return false;

0 commit comments

Comments
 (0)