thread safety and performance improv

This commit is contained in:
rootdarkarchon
2023-04-04 13:54:33 +02:00
parent a4d9207506
commit 1e9d4998ce
4 changed files with 42 additions and 24 deletions

View File

@@ -105,11 +105,10 @@ public sealed class FileCacheManager : IDisposable
public FileCacheEntity? GetFileCacheByHash(string hash)
{
if (_fileCaches.Any(f => string.Equals(f.Value.Hash, hash, StringComparison.Ordinal)))
var entry = _fileCaches.FirstOrDefault(f => string.Equals(f.Value.Hash, hash, StringComparison.Ordinal));
if (!EqualityComparer<KeyValuePair<string, FileCacheEntity>>.Default.Equals(entry, default))
{
return GetValidatedFileCache(_fileCaches.Where(f => string.Equals(f.Value.Hash, hash, StringComparison.Ordinal))
.OrderByDescending(f => f.Value.PrefixedFilePath.Length)
.FirstOrDefault(f => string.Equals(f.Value.Hash, hash, StringComparison.Ordinal)).Value);
return GetValidatedFileCache(entry.Value);
}
return null;