mirror of
https://github.com/oliverbooth/fdup.git
synced 2024-12-05 01:28:47 +00:00
fix: use ConcurrentBag for hash cache
This commit is contained in:
parent
3396c2bc74
commit
7da6faff83
@ -8,7 +8,7 @@ namespace FindDuplicates;
|
|||||||
|
|
||||||
internal sealed class ListCommand : AsyncCommand<ListSettings>
|
internal sealed class ListCommand : AsyncCommand<ListSettings>
|
||||||
{
|
{
|
||||||
private readonly ConcurrentDictionary<string, List<FileInfo>> _fileHashMap = new();
|
private readonly ConcurrentDictionary<string, ConcurrentBag<FileInfo>> _fileHashMap = new();
|
||||||
|
|
||||||
public override async Task<int> ExecuteAsync(CommandContext context, ListSettings settings)
|
public override async Task<int> ExecuteAsync(CommandContext context, ListSettings settings)
|
||||||
{
|
{
|
||||||
@ -29,7 +29,7 @@ internal sealed class ListCommand : AsyncCommand<ListSettings>
|
|||||||
AnsiConsole.WriteLine();
|
AnsiConsole.WriteLine();
|
||||||
|
|
||||||
int duplicates = 0;
|
int duplicates = 0;
|
||||||
foreach ((string hash, List<FileInfo> files) in _fileHashMap)
|
foreach ((string hash, ConcurrentBag<FileInfo> files) in _fileHashMap)
|
||||||
{
|
{
|
||||||
int fileCount = files.Count;
|
int fileCount = files.Count;
|
||||||
|
|
||||||
@ -119,11 +119,8 @@ internal sealed class ListCommand : AsyncCommand<ListSettings>
|
|||||||
if (settings.Verbose)
|
if (settings.Verbose)
|
||||||
AnsiConsole.WriteLine($"{file.FullName} ->\n {hash}");
|
AnsiConsole.WriteLine($"{file.FullName} ->\n {hash}");
|
||||||
|
|
||||||
if (!_fileHashMap.TryGetValue(hash, out List<FileInfo>? cache))
|
ConcurrentBag<FileInfo> cache = _fileHashMap.GetOrAdd(hash, _ => []);
|
||||||
_fileHashMap[hash] = cache = new List<FileInfo>();
|
cache.Add(file);
|
||||||
|
|
||||||
lock (cache)
|
|
||||||
cache.Add(file);
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user