Sollte ich ReadonlySpan <Arghor> als Schlüssel verwenden, in gleichzeitiger Verfassung anstelle von String, um eine bess
Posted: 10 Apr 2025, 00:40
Der Quellcode für die gleichzeitige Verfassung erwähnt die Möglichkeit, TalternateKey zu verwenden, was eine Ref -Struktur ist.
https://github.com/dotnet/runtime/blob/ ... tionary.cs
Auch nach einiger Suche fand ich andere Beispiele. Wie hier:
https://github.com/dotnet/runtime/blob/ ... ache.cs./p>
Sollte ich ReadOnlySpan als Schlüssel verwenden, in gleichzeitiger Verfassung anstelle von String für eine bessere Leistung?
https://github.com/dotnet/runtime/blob/ ... tionary.cs
Auch nach einiger Suche fand ich andere Beispiele. Wie hier:
https://github.com/dotnet/runtime/blob/ ... ache.cs./p>
Code: Select all
#if NET9_0_OR_GREATER
private readonly ConcurrentDictionary.AlternateLookup _stringAltLookup;
public CoherentState()
{
_stringAltLookup = _stringEntries.GetAlternateLookup();
}
#endif
//...
#if NET9_0_OR_GREATER
internal bool TryGetValue(ReadOnlySpan key, [NotNullWhen(true)] out CacheEntry? entry)
=> _stringAltLookup.TryGetValue(key, out entry);
#endif
#if NET9_0_OR_GREATER
private readonly ConcurrentDictionary.AlternateLookup _stringAltLookup;
public CoherentState()
{
_stringAltLookup = _stringEntries.GetAlternateLookup();
}
#endif