Skip to content

Commit a566f9f

Browse files
committed
Avoid "continue outer loop" in ExplodeLoop loop for clarity
* And to avoid too many loop explosions when changing the ExplodeLoop kind.
1 parent 58e7a47 commit a566f9f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/main/java/org/truffleruby/core/hash/HashLiteralNode.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*/
1010
package org.truffleruby.core.hash;
1111

12-
import com.oracle.truffle.api.nodes.ExplodeLoop.LoopExplosionKind;
1312
import org.truffleruby.Layouts;
1413
import org.truffleruby.RubyContext;
1514
import org.truffleruby.core.cast.BooleanCastNode;
@@ -72,33 +71,37 @@ public SmallHashLiteralNode(RubyNode[] keyValues) {
7271
super(keyValues);
7372
}
7473

75-
@ExplodeLoop(kind = LoopExplosionKind.FULL_UNROLL)
74+
@ExplodeLoop
7675
@Override
7776
public Object execute(VirtualFrame frame) {
7877
final Object[] store = PackedArrayStrategy.createStore(getContext());
7978

8079
int size = 0;
8180

82-
initializers: for (int n = 0; n < keyValues.length / 2; n++) {
81+
for (int n = 0; n < keyValues.length / 2; n++) {
8382
Object key = keyValues[n * 2].execute(frame);
8483
key = freezeHashKeyIfNeededNode.executeFreezeIfNeeded(key, false);
8584

8685
final int hashed = hash(key);
8786

8887
final Object value = keyValues[n * 2 + 1].execute(frame);
88+
boolean duplicateKey = false;
8989

9090
for (int i = 0; i < n; i++) {
9191
if (i < size &&
9292
hashed == PackedArrayStrategy.getHashed(store, i) &&
9393
callEqual(key, PackedArrayStrategy.getKey(store, i))) {
9494
PackedArrayStrategy.setKey(store, i, key);
9595
PackedArrayStrategy.setValue(store, i, value);
96-
continue initializers;
96+
duplicateKey = true;
97+
break;
9798
}
9899
}
99100

100-
PackedArrayStrategy.setHashedKeyValue(store, size, hashed, key, value);
101-
size++;
101+
if (!duplicateKey) {
102+
PackedArrayStrategy.setHashedKeyValue(store, size, hashed, key, value);
103+
size++;
104+
}
102105
}
103106

104107
return coreLibrary()

0 commit comments

Comments
 (0)