54
54
@ GenerateUncached
55
55
public class BucketsHashStore {
56
56
57
- private Entry [] entries ;
57
+ private final Entry [] entries ;
58
58
59
59
public BucketsHashStore (Entry [] entries ) {
60
60
this .entries = entries ;
@@ -178,9 +178,9 @@ private static void removeFromSequenceChain(RubyHash hash, Entry entry) {
178
178
}
179
179
}
180
180
181
- private static void removeFromLookupChain (RubyHash hash , int index , Entry entry , Entry previousEntry ) {
181
+ private static void removeFromLookupChain (Entry [] entries , int index , Entry entry , Entry previousEntry ) {
182
182
if (previousEntry == null ) {
183
- (( BucketsHashStore ) hash . store ). entries [index ] = entry .getNextInLookup ();
183
+ entries [index ] = entry .getNextInLookup ();
184
184
} else {
185
185
previousEntry .setNextInLookup (entry .getNextInLookup ());
186
186
}
@@ -194,7 +194,8 @@ protected Object lookupOrDefault(Frame frame, RubyHash hash, Object key, PEBiFun
194
194
@ Cached @ Shared ("lookup" ) LookupEntryNode lookup ,
195
195
@ Cached @ Exclusive ConditionProfile found ) {
196
196
197
- final HashLookupResult hashLookupResult = lookup .execute (hash , key );
197
+ final Entry [] entries = this .entries ;
198
+ final HashLookupResult hashLookupResult = lookup .execute (hash , entries , key );
198
199
199
200
if (found .profile (hashLookupResult .getEntry () != null )) {
200
201
return hashLookupResult .getEntry ().getValue ();
@@ -213,14 +214,15 @@ protected boolean set(RubyHash hash, Object key, Object value, boolean byIdentit
213
214
@ Cached @ Exclusive ConditionProfile bucketCollision ,
214
215
@ Cached @ Exclusive ConditionProfile appending ,
215
216
@ Cached @ Exclusive ConditionProfile resize ) {
216
-
217
217
assert verify (hash );
218
+
218
219
final Object key2 = freezeHashKeyIfNeeded .executeFreezeIfNeeded (key , byIdentity );
219
220
220
221
propagateSharingKey .executePropagate (hash , key2 );
221
222
propagateSharingValue .executePropagate (hash , value );
222
223
223
- final HashLookupResult result = lookup .execute (hash , key2 );
224
+ final Entry [] entries = this .entries ;
225
+ final HashLookupResult result = lookup .execute (hash , entries , key2 );
224
226
final Entry entry = result .getEntry ();
225
227
226
228
if (missing .profile (entry == null )) {
@@ -260,17 +262,18 @@ protected boolean set(RubyHash hash, Object key, Object value, boolean byIdentit
260
262
protected Object delete (RubyHash hash , Object key ,
261
263
@ Cached @ Shared ("lookup" ) LookupEntryNode lookup ,
262
264
@ Cached @ Exclusive ConditionProfile missing ) {
263
-
264
265
assert verify (hash );
265
- final HashLookupResult lookupResult = lookup .execute (hash , key );
266
+
267
+ final Entry [] entries = this .entries ;
268
+ final HashLookupResult lookupResult = lookup .execute (hash , entries , key );
266
269
final Entry entry = lookupResult .getEntry ();
267
270
268
271
if (missing .profile (entry == null )) {
269
272
return null ;
270
273
}
271
274
272
275
removeFromSequenceChain (hash , entry );
273
- removeFromLookupChain (hash , lookupResult .getIndex (), entry , lookupResult .getPreviousEntry ());
276
+ removeFromLookupChain (entries , lookupResult .getIndex (), entry , lookupResult .getPreviousEntry ());
274
277
hash .size -= 1 ;
275
278
assert verify (hash );
276
279
return entry .getValue ();
@@ -280,6 +283,8 @@ protected Object delete(RubyHash hash, Object key,
280
283
protected Object deleteLast (RubyHash hash , Object key ,
281
284
@ Cached @ Exclusive ConditionProfile singleEntry ) {
282
285
assert verify (hash );
286
+
287
+ final Entry [] entries = this .entries ;
283
288
final Entry lastEntry = hash .lastInSequence ;
284
289
if (key != lastEntry .getKey ()) {
285
290
CompilerDirectives .transferToInterpreterAndInvalidate ();
@@ -308,7 +313,7 @@ protected Object deleteLast(RubyHash hash, Object key,
308
313
hash .lastInSequence = previousInSequence ;
309
314
}
310
315
311
- removeFromLookupChain (hash , index , entry , previousEntry );
316
+ removeFromLookupChain (entries , index , entry , previousEntry );
312
317
hash .size -= 1 ;
313
318
assert verify (hash );
314
319
return entry .getValue ();
@@ -351,7 +356,8 @@ protected void replace(RubyHash hash, RubyHash dest,
351
356
propagateSharing .executePropagate (dest , hash );
352
357
assert verify (hash );
353
358
354
- final Entry [] newEntries = new Entry [((BucketsHashStore ) hash .store ).entries .length ];
359
+ final Entry [] entries = ((BucketsHashStore ) hash .store ).entries ;
360
+ final Entry [] newEntries = new Entry [entries .length ];
355
361
356
362
Entry firstInSequence = null ;
357
363
Entry lastInSequence = null ;
@@ -390,6 +396,7 @@ protected RubyArray shift(RubyHash hash,
390
396
391
397
assert verify (hash );
392
398
399
+ final Entry [] entries = this .entries ;
393
400
final Entry first = hash .firstInSequence ;
394
401
assert first .getPreviousInSequence () == null ;
395
402
@@ -407,7 +414,7 @@ protected RubyArray shift(RubyHash hash,
407
414
hash .lastInSequence = null ;
408
415
}
409
416
410
- final int index = getBucketIndex (first .getHashed (), this . entries .length );
417
+ final int index = getBucketIndex (first .getHashed (), entries .length );
411
418
412
419
Entry previous = null ;
413
420
Entry entry = entries [index ];
@@ -437,6 +444,7 @@ protected void rehash(RubyHash hash,
437
444
@ Cached HashingNodes .ToHash hashNode ) {
438
445
439
446
assert verify (hash );
447
+ final Entry [] entries = this .entries ;
440
448
Arrays .fill (entries , null );
441
449
442
450
Entry entry = hash .firstInSequence ;
@@ -483,6 +491,7 @@ protected void rehash(RubyHash hash,
483
491
public boolean verify (RubyHash hash ) {
484
492
assert hash .store == this ;
485
493
494
+ final Entry [] entries = this .entries ;
486
495
final int size = hash .size ;
487
496
final Entry firstInSequence = hash .firstInSequence ;
488
497
final Entry lastInSequence = hash .lastInSequence ;
@@ -538,17 +547,16 @@ public boolean verify(RubyHash hash) {
538
547
@ GenerateUncached
539
548
abstract static class LookupEntryNode extends RubyBaseNode {
540
549
541
- public abstract HashLookupResult execute (RubyHash hash , Object key );
550
+ public abstract HashLookupResult execute (RubyHash hash , Entry [] entries , Object key );
542
551
543
552
@ Specialization
544
- protected HashLookupResult lookup (RubyHash hash , Object key ,
553
+ protected HashLookupResult lookup (RubyHash hash , Entry [] entries , Object key ,
545
554
@ Cached HashingNodes .ToHash hashNode ,
546
555
@ Cached CompareHashKeysNode compareHashKeysNode ,
547
556
@ Cached ConditionProfile byIdentityProfile ) {
548
557
final boolean compareByIdentity = byIdentityProfile .profile (hash .compareByIdentity );
549
558
int hashed = hashNode .execute (key , compareByIdentity );
550
559
551
- final Entry [] entries = ((BucketsHashStore ) hash .store ).entries ;
552
560
final int index = getBucketIndex (hashed , entries .length );
553
561
Entry entry = entries [index ];
554
562
0 commit comments