Skip to content

Commit baabd5c

Browse files
committed
[GR-32640] Read entries from the Hash only once
PullRequest: truffleruby/2810
2 parents d63684a + 1093cf2 commit baabd5c

File tree

7 files changed

+105
-141
lines changed

7 files changed

+105
-141
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public abstract static class AllocateNode extends CoreMethodArrayArgumentsNode {
5858
protected RubyHash allocate(RubyClass rubyClass) {
5959
final Shape shape = getLanguage().hashShape;
6060
final EmptyHashStore store = EmptyHashStore.NULL_HASH_STORE;
61-
final RubyHash hash = new RubyHash(rubyClass, shape, getContext(), store, 0, null, null, nil, nil, false);
61+
final RubyHash hash = new RubyHash(rubyClass, shape, getContext(), store, 0);
6262
AllocationTracing.trace(hash, this);
6363
return hash;
6464
}
@@ -109,7 +109,7 @@ protected Object construct(RubyClass hashClass, Object[] args,
109109
}
110110

111111
final Shape shape = getLanguage().hashShape;
112-
return new RubyHash(hashClass, shape, getContext(), newStore, size, null, null, nil, nil, false);
112+
return new RubyHash(hashClass, shape, getContext(), newStore, size);
113113
}
114114

115115
@Specialization(guards = "!isSmallArrayOfPairs(args, getLanguage())")

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,17 @@
1414
import org.truffleruby.core.hash.library.EmptyHashStore;
1515
import org.truffleruby.core.numeric.BigIntegerOps;
1616
import org.truffleruby.core.numeric.RubyBignum;
17-
import org.truffleruby.language.Nil;
1817
import org.truffleruby.language.RubyBaseNode;
1918

2019
public abstract class HashOperations {
2120

2221
public static RubyHash newEmptyHash(RubyContext context, RubyLanguage language) {
23-
final Object nil = Nil.INSTANCE;
2422
return new RubyHash(
2523
context.getCoreLibrary().hashClass,
2624
language.hashShape,
2725
context,
2826
EmptyHashStore.NULL_HASH_STORE,
29-
0,
30-
null,
31-
null,
32-
nil,
33-
nil,
34-
false);
27+
0);
3528
}
3629

3730
// random number, stops hashes for similar values but different classes being the same, static because we want deterministic hashes

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

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.truffleruby.core.hash.library.HashStoreLibrary;
3333
import org.truffleruby.core.klass.RubyClass;
3434
import org.truffleruby.interop.ForeignToRubyNode;
35+
import org.truffleruby.language.Nil;
3536
import org.truffleruby.language.RubyDynamicObject;
3637
import org.truffleruby.language.dispatch.DispatchNode;
3738
import org.truffleruby.language.library.RubyLibrary;
@@ -42,12 +43,10 @@
4243
@ImportStatic(HashGuards.class)
4344
public class RubyHash extends RubyDynamicObject implements ObjectGraphNode {
4445

45-
public Object defaultBlock;
46-
public Object defaultValue;
4746
public Object store;
4847
public int size;
49-
public Entry firstInSequence;
50-
public Entry lastInSequence;
48+
public Object defaultBlock;
49+
public Object defaultValue;
5150
public boolean compareByIdentity;
5251
public boolean ruby2_keywords = false;
5352

@@ -56,20 +55,13 @@ public RubyHash(
5655
Shape shape,
5756
RubyContext context,
5857
Object store,
59-
int size,
60-
Entry firstInSequence,
61-
Entry lastInSequence,
62-
Object defaultBlock,
63-
Object defaultValue,
64-
boolean compareByIdentity) {
58+
int size) {
6559
super(rubyClass, shape);
66-
this.defaultBlock = defaultBlock;
67-
this.defaultValue = defaultValue;
6860
this.store = store;
6961
this.size = size;
70-
this.firstInSequence = firstInSequence;
71-
this.lastInSequence = lastInSequence;
72-
this.compareByIdentity = compareByIdentity;
62+
this.defaultBlock = Nil.INSTANCE;
63+
this.defaultValue = Nil.INSTANCE;
64+
this.compareByIdentity = false;
7365

7466
if (context.isPreInitializing()) {
7567
context.getPreInitializationManager().addPreInitHash(this);
@@ -79,7 +71,7 @@ public RubyHash(
7971
@TruffleBoundary
8072
public void getAdjacentObjects(Set<Object> reachable) {
8173
if (store instanceof BucketsHashStore) {
82-
BucketsHashStore.getAdjacentObjects(reachable, firstInSequence);
74+
((BucketsHashStore) store).getAdjacentObjects(reachable);
8375
} else {
8476
ObjectGraph.addProperty(reachable, store);
8577
}

0 commit comments

Comments
 (0)