@@ -259,9 +259,17 @@ public bool TryGetValue(int index, out T value)
259259 }
260260
261261 IndexToSlot ( index , out var bucketIndex , out var itemIndex ) ;
262- ref var item = ref GetBucket ( bucketIndex ) [ itemIndex ] ;
263-
262+
263+ // Bucket empty? return false
264+ ref var bucket = ref GetBucket ( bucketIndex ) ;
265+ if ( bucket . IsEmpty )
266+ {
267+ value = _filler ;
268+ return false ;
269+ }
270+
264271 // If the item is the default then the nobody set its value.
272+ ref var item = ref bucket [ itemIndex ] ;
265273 if ( EqualityComparer < T > . Default . Equals ( item , _filler ) )
266274 {
267275 value = _filler ;
@@ -289,9 +297,17 @@ public ref T TryGetValue(int index, out bool @bool)
289297 }
290298
291299 IndexToSlot ( index , out var bucketIndex , out var itemIndex ) ;
292- ref var item = ref GetBucket ( bucketIndex ) [ itemIndex ] ;
293-
300+
301+ // Bucket empty? return false
302+ ref var bucket = ref GetBucket ( bucketIndex ) ;
303+ if ( bucket . IsEmpty )
304+ {
305+ @bool = false ;
306+ return ref Unsafe . NullRef < T > ( ) ;
307+ }
308+
294309 // If the item is the default then the nobody set its value.
310+ ref var item = ref bucket [ itemIndex ] ;
295311 if ( EqualityComparer < T > . Default . Equals ( item , _filler ) )
296312 {
297313 @bool = false ;
@@ -316,8 +332,9 @@ public bool ContainsKey(int index)
316332 }
317333
318334 IndexToSlot ( index , out var bucketIndex , out var itemIndex ) ;
319- ref var bucket = ref GetBucket ( bucketIndex ) ;
320335
336+ // If bucket empty return false
337+ ref var bucket = ref GetBucket ( bucketIndex ) ;
321338 if ( bucket . IsEmpty )
322339 {
323340 return false ;
0 commit comments