@@ -24,7 +24,7 @@ namespace IronPython.Runtime {
24
24
/// Mutations to the dictionary involves a simple locking strategy of
25
25
/// locking on the DictionaryStorage object to ensure that only one
26
26
/// mutation happens at a time.
27
- ///
27
+ ///
28
28
/// Reads against the dictionary happen lock free. When the dictionary is mutated
29
29
/// it is either adding or removing buckets in a thread-safe manner so that the readers
30
30
/// will either see a consistent picture as if the read occured before or after the mutation.
@@ -161,11 +161,12 @@ public void AddNoLock(object key, object value) {
161
161
}
162
162
163
163
private void AddOne ( object key , object value ) {
164
- GetHash ( key , out var hc , out var eqFunc ) ;
165
- if ( AddWorker ( _indices , _buckets , new Bucket ( key , value , hc ) , eqFunc ) ) {
164
+ Debug . Assert ( _keyType == HeterogeneousType || key ? . GetType ( ) == _keyType ) ;
165
+ var hc = _hashFunc ( key ) & int . MaxValue ;
166
+ if ( AddWorker ( _indices , _buckets , new Bucket ( key , value , hc ) , _eqFunc ) ) {
166
167
if ( _count >= ( _indices . Length * Load ) ) {
167
168
// grow the hash table
168
- EnsureSize ( ( int ) ( _indices . Length / Load ) * ResizeMultiplier , eqFunc ) ;
169
+ EnsureSize ( ( int ) ( _indices . Length / Load ) * ResizeMultiplier , _eqFunc ) ;
169
170
}
170
171
}
171
172
}
@@ -298,7 +299,9 @@ private static KeyValuePair<int, int> LookupIndex(int[] indices, List<Bucket> bu
298
299
}
299
300
300
301
// keep walking
301
- index = ProbeNext ( indices , index ) ;
302
+ if ( ++ index == indices . Length ) {
303
+ index = 0 ;
304
+ }
302
305
303
306
// if we ended up doing a full scan, then this means the key is not already in use and there are
304
307
// only recycled buckets available -- nothing more to probe
@@ -329,15 +332,6 @@ private bool AddWorker(int[] indices, List<Bucket> buckets, Bucket bucket, Func<
329
332
return true ;
330
333
}
331
334
332
- private static int ProbeNext ( int [ ] indices , int index ) {
333
- // probe to next bucket
334
- index ++ ;
335
- if ( index == indices . Length ) {
336
- index = 0 ;
337
- }
338
- return index ;
339
- }
340
-
341
335
/// <summary>
342
336
/// Removes an entry from the dictionary and returns true if the
343
337
/// entry was removed or false.
@@ -389,10 +383,7 @@ private void GetHash(object key, out int hc, out Func<object, object, bool> eqFu
389
383
390
384
private bool TryRemoveNoLock ( object key , out object value ) {
391
385
GetHash ( key , out var hc , out var eqFunc ) ;
392
- return TryRemoveNoLock ( key , hc , eqFunc , out value ) ;
393
- }
394
386
395
- private bool TryRemoveNoLock ( object key , int hc , Func < object , object , bool > eqFunc , out object value ) {
396
387
if ( _indices == null ) {
397
388
value = null ;
398
389
return false ;
@@ -445,22 +436,19 @@ public override bool TryGetValue(object key, out object value)
445
436
private bool TryGetValue ( int [ ] indices , List < Bucket > buckets , object key , out object value ) {
446
437
if ( _count > 0 && indices != null ) {
447
438
GetHash ( key , out var hc , out var eqFunc ) ;
448
- return TryGetValue ( indices , buckets , key , hc , eqFunc , out value ) ;
449
- }
450
439
451
- value = null ;
452
- return false ;
453
- }
440
+ var pair = LookupIndex ( indices , buckets , key , hc , eqFunc ) ;
441
+ if ( pair . Value < 0 ) {
442
+ value = null ;
443
+ return false ;
444
+ }
454
445
455
- private static bool TryGetValue ( int [ ] indices , List < Bucket > buckets , object key , int hc , Func < object , object , bool > eqFunc , out object value ) {
456
- var pair = LookupIndex ( indices , buckets , key , hc , eqFunc ) ;
457
- if ( pair . Value < 0 ) {
458
- value = null ;
459
- return false ;
446
+ value = buckets [ pair . Value ] . Value ;
447
+ return true ;
460
448
}
461
449
462
- value = buckets [ pair . Value ] . Value ;
463
- return true ;
450
+ value = null ;
451
+ return false ;
464
452
}
465
453
466
454
/// <summary>
0 commit comments