Skip to content

Commit e6cf36c

Browse files
committed
Add a profile for the unlikely case of a duplicate key in a Hash literal
1 parent a566f9f commit e6cf36c

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

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

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

12+
import com.oracle.truffle.api.profiles.BranchProfile;
1213
import org.truffleruby.Layouts;
1314
import org.truffleruby.RubyContext;
1415
import org.truffleruby.core.cast.BooleanCastNode;
@@ -66,6 +67,7 @@ public static class SmallHashLiteralNode extends HashLiteralNode {
6667
@Child private CallDispatchHeadNode equalNode;
6768
@Child private BooleanCastNode booleanCastNode;
6869
@Child private FreezeHashKeyIfNeededNode freezeHashKeyIfNeededNode = FreezeHashKeyIfNeededNodeGen.create();
70+
private final BranchProfile duplicateKeyProfile = BranchProfile.create();
6971

7072
public SmallHashLiteralNode(RubyNode[] keyValues) {
7173
super(keyValues);
@@ -91,6 +93,7 @@ public Object execute(VirtualFrame frame) {
9193
if (i < size &&
9294
hashed == PackedArrayStrategy.getHashed(store, i) &&
9395
callEqual(key, PackedArrayStrategy.getKey(store, i))) {
96+
duplicateKeyProfile.enter();
9497
PackedArrayStrategy.setKey(store, i, key);
9598
PackedArrayStrategy.setValue(store, i, value);
9699
duplicateKey = true;

0 commit comments

Comments
 (0)