Make ItemDictionary responsible for running filters on itself

This commit is contained in:
Matt Nadareski
2024-03-19 14:25:54 -04:00
parent eec50e3d48
commit 5cda1c8b8f
2 changed files with 47 additions and 35 deletions

View File

@@ -158,41 +158,7 @@ namespace SabreTools.DatFiles
/// </summary>
/// <param name="filterRunner">Preconfigured filter runner to use</param>
public void ExecuteFilters(FilterRunner filterRunner)
{
List<string> keys = [.. Items.Keys];
#if NET452_OR_GREATER || NETCOREAPP
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
#elif NET40_OR_GREATER
Parallel.ForEach(keys, key =>
#else
foreach (var key in keys)
#endif
{
ConcurrentList<DatItem>? items = Items[key];
if (items == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
// Filter all items in the current key
var newItems = new ConcurrentList<DatItem>();
foreach (var item in items)
{
if (item.PassesFilter(filterRunner))
newItems.Add(item);
}
// Set the value in the key to the new set
Items[key] = newItems;
#if NET40_OR_GREATER || NETCOREAPP
});
#else
}
#endif
}
=> Items.ExecuteFilters(filterRunner);
#endregion