Skip to content

Commit 220bd81

Browse files
committed
Refactor SmallHashLiteralNode to DSL node
1 parent 40638ed commit 220bd81

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.truffleruby.core.hash.library.BucketsHashStore;
1313
import org.truffleruby.core.hash.library.EmptyHashStore;
1414
import org.truffleruby.core.hash.library.PackedHashStoreLibrary;
15+
import org.truffleruby.core.hash.library.PackedHashStoreLibraryFactory;
1516
import org.truffleruby.language.RubyContextSourceNode;
1617
import org.truffleruby.language.RubyNode;
1718

@@ -31,7 +32,7 @@ public static HashLiteralNode create(RubyNode[] keyValues) {
3132
if (keyValues.length == 0) {
3233
return new EmptyHashStore.EmptyHashLiteralNode();
3334
} else if (keyValues.length <= PackedHashStoreLibrary.MAX_ENTRIES * 2) {
34-
return new PackedHashStoreLibrary.SmallHashLiteralNode(keyValues);
35+
return PackedHashStoreLibraryFactory.SmallHashLiteralNodeGen.create(keyValues);
3536
} else {
3637
return new BucketsHashStore.GenericHashLiteralNode(keyValues);
3738
}

src/main/java/org/truffleruby/core/hash/library/PackedHashStoreLibrary.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import com.oracle.truffle.api.nodes.ExplodeLoop;
2828
import com.oracle.truffle.api.nodes.ExplodeLoop.LoopExplosionKind;
2929
import com.oracle.truffle.api.nodes.Node;
30-
import com.oracle.truffle.api.profiles.BranchProfile;
3130
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
3231
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
3332
import com.oracle.truffle.api.profiles.LoopConditionProfile;
@@ -41,7 +40,6 @@
4140
import org.truffleruby.core.hash.CompareHashKeysNode;
4241
import org.truffleruby.core.hash.Entry;
4342
import org.truffleruby.core.hash.FreezeHashKeyIfNeededNode;
44-
import org.truffleruby.core.hash.FreezeHashKeyIfNeededNodeGen;
4543
import org.truffleruby.core.hash.HashGuards;
4644
import org.truffleruby.core.hash.HashLiteralNode;
4745
import org.truffleruby.core.hash.HashingNodes;
@@ -52,6 +50,7 @@
5250
import org.truffleruby.language.dispatch.DispatchNode;
5351
import org.truffleruby.language.objects.shared.PropagateSharingNode;
5452
import org.truffleruby.language.objects.shared.SharedObjects;
53+
import org.truffleruby.core.hash.library.PackedHashStoreLibraryFactory.SmallHashLiteralNodeGen;
5554

5655
@ExportLibrary(value = HashStoreLibrary.class, receiverType = Object[].class)
5756
@GenerateUncached
@@ -481,21 +480,21 @@ protected boolean equalKeys(CompareHashKeysNode compareHashKeys, boolean compare
481480
}
482481
}
483482

484-
public static class SmallHashLiteralNode extends HashLiteralNode {
483+
public abstract static class SmallHashLiteralNode extends HashLiteralNode {
485484

486485
@Child private HashingNodes.ToHashByHashCode hashNode;
487486
@Child private DispatchNode equalNode;
488487
@Child private BooleanCastNode booleanCastNode;
489-
@Child private FreezeHashKeyIfNeededNode freezeHashKeyIfNeededNode = FreezeHashKeyIfNeededNodeGen.create();
490-
private final BranchProfile duplicateKeyProfile = BranchProfile.create();
491488

492489
public SmallHashLiteralNode(RubyNode[] keyValues) {
493490
super(keyValues);
494491
}
495492

493+
@Specialization
496494
@ExplodeLoop
497-
@Override
498-
public Object execute(VirtualFrame frame) {
495+
protected Object doHash(VirtualFrame frame,
496+
@Cached InlinedBranchProfile duplicateKeyProfile,
497+
@Cached FreezeHashKeyIfNeededNode freezeHashKeyIfNeededNode) {
499498
final Object[] store = createStore();
500499
int size = 0;
501500

@@ -512,7 +511,7 @@ public Object execute(VirtualFrame frame) {
512511
if (i < size &&
513512
hashed == getHashed(store, i) &&
514513
callEqual(key, getKey(store, i))) {
515-
duplicateKeyProfile.enter();
514+
duplicateKeyProfile.enter(this);
516515
setKey(store, i, key);
517516
setValue(store, i, value);
518517
duplicateKey = true;
@@ -559,7 +558,7 @@ private boolean callEqual(Object receiver, Object key) {
559558

560559
@Override
561560
public RubyNode cloneUninitialized() {
562-
var copy = new SmallHashLiteralNode(cloneUninitialized(keyValues));
561+
var copy = SmallHashLiteralNodeGen.create(cloneUninitialized(keyValues));
563562
return copy.copyFlags(this);
564563
}
565564

0 commit comments

Comments
 (0)