@@ -211,10 +211,7 @@ public bool TryGetValue(object key, out object? result)
211
211
DateTime utcNow = UtcNow ;
212
212
213
213
CoherentState coherentState = _coherentState ; // Clear() can update the reference in the meantime
214
- if ( ! coherentState . TryGetValue ( key , out CacheEntry ? entry ) )
215
- {
216
- entry = null ;
217
- }
214
+ coherentState . TryGetValue ( key , out CacheEntry ? entry ) ; // note we rely on documented "default when fails" contract re the out
218
215
return PostProcessTryGetValue ( coherentState , utcNow , entry , out result ) ;
219
216
}
220
217
@@ -234,10 +231,7 @@ public bool TryGetValue(ReadOnlySpan<char> key, out object? result)
234
231
DateTime utcNow = UtcNow ;
235
232
236
233
CoherentState coherentState = _coherentState ; // Clear() can update the reference in the meantime
237
- if ( ! coherentState . TryGetValue ( key , out CacheEntry ? entry ) )
238
- {
239
- entry = null ;
240
- }
234
+ coherentState . TryGetValue ( key , out CacheEntry ? entry ) ; // note we rely on documented "default when fails" contract re the out
241
235
return PostProcessTryGetValue ( coherentState , utcNow , entry , out result ) ;
242
236
}
243
237
@@ -738,14 +732,11 @@ private sealed class CoherentState
738
732
private readonly ConcurrentDictionary < object , CacheEntry > _nonStringEntries = new ConcurrentDictionary < object , CacheEntry > ( ) ;
739
733
740
734
#if NET9_0_OR_GREATER
741
- private readonly bool _useStringAltLookup ;
742
735
private readonly ConcurrentDictionary < string , CacheEntry > . AlternateLookup < ReadOnlySpan < char > > _stringAltLookup ;
743
736
744
737
public CoherentState ( )
745
738
{
746
- _useStringAltLookup = _stringEntries . TryGetAlternateLookup < ReadOnlySpan < char > > ( out _stringAltLookup ) ;
747
- // we *expect* this to be available in all scenarios where this is used, but add a dev guard, and a fallback
748
- Debug . Assert ( _useStringAltLookup , "Expectation failure: alt-lookup feature is not available" ) ;
739
+ _stringAltLookup = _stringEntries . GetAlternateLookup < ReadOnlySpan < char > > ( ) ;
749
740
}
750
741
#endif
751
742
@@ -756,8 +747,7 @@ internal bool TryGetValue(object key, [NotNullWhen(true)] out CacheEntry? entry)
756
747
757
748
#if NET9_0_OR_GREATER
758
749
internal bool TryGetValue ( ReadOnlySpan < char > key , [ NotNullWhen ( true ) ] out CacheEntry ? entry )
759
- => _useStringAltLookup ? _stringAltLookup . TryGetValue ( key , out entry )
760
- : _stringEntries . TryGetValue ( new string ( key ) , out entry ) ; // <== we do not expect this path to be hit; chaos fallback only
750
+ => _stringAltLookup . TryGetValue ( key , out entry ) ;
761
751
#endif
762
752
763
753
0 commit comments