Skip to content

Commit 1093cf2

Browse files
committed
Set common initial values for RubyHash in the constructor
1 parent 000b1c0 commit 1093cf2

File tree

5 files changed

+12
-25
lines changed

5 files changed

+12
-25
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, 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, 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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +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-
nil,
31-
nil,
32-
false);
27+
0);
3328
}
3429

3530
// 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: 7 additions & 9 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,10 +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;
48+
public Object defaultBlock;
49+
public Object defaultValue;
4950
public boolean compareByIdentity;
5051
public boolean ruby2_keywords = false;
5152

@@ -54,16 +55,13 @@ public RubyHash(
5455
Shape shape,
5556
RubyContext context,
5657
Object store,
57-
int size,
58-
Object defaultBlock,
59-
Object defaultValue,
60-
boolean compareByIdentity) {
58+
int size) {
6159
super(rubyClass, shape);
62-
this.defaultBlock = defaultBlock;
63-
this.defaultValue = defaultValue;
6460
this.store = store;
6561
this.size = size;
66-
this.compareByIdentity = compareByIdentity;
62+
this.defaultBlock = Nil.INSTANCE;
63+
this.defaultValue = Nil.INSTANCE;
64+
this.compareByIdentity = false;
6765

6866
if (context.isPreInitializing()) {
6967
context.getPreInitializationManager().addPreInitHash(this);

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,7 @@ public Object execute(VirtualFrame frame) {
606606
getLanguage().hashShape,
607607
getContext(),
608608
new BucketsHashStore(new Entry[bucketsCount], null, null),
609-
0,
610-
nil,
611-
nil,
612-
false);
609+
0);
613610

614611
for (int n = 0; n < keyValues.length; n += 2) {
615612
final Object key = keyValues[n].execute(frame);

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,7 @@ public Object execute(VirtualFrame frame) {
524524
getLanguage().hashShape,
525525
getContext(),
526526
store,
527-
size,
528-
nil,
529-
nil,
530-
false);
527+
size);
531528
}
532529

533530
private int hash(Object key) {

0 commit comments

Comments
 (0)