Parallelize RemoveBiosAndDeviceSets*

This commit is contained in:
Matt Nadareski
2025-05-11 21:29:34 -04:00
parent e7add2c0ae
commit f95a233bc0

View File

@@ -1021,17 +1021,32 @@ namespace SabreTools.DatFiles
private void RemoveBiosAndDeviceSetsImpl() private void RemoveBiosAndDeviceSetsImpl()
{ {
string[] buckets = [.. Items.SortedKeys]; string[] buckets = [.. Items.SortedKeys];
#if NET452_OR_GREATER || NETCOREAPP
Parallel.ForEach(buckets, Globals.ParallelOptions, bucket =>
#elif NET40_OR_GREATER
Parallel.ForEach(buckets, bucket =>
#else
foreach (string bucket in buckets) foreach (string bucket in buckets)
#endif
{ {
// If the bucket has no items in it // If the bucket has no items in it
List<DatItem> items = GetItemsForBucket(bucket); List<DatItem> items = GetItemsForBucket(bucket);
if (items.Count == 0) if (items.Count == 0)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue; continue;
#endif
// Get the machine // Get the machine
var machine = items[0].GetMachine(); var machine = items[0].GetMachine();
if (machine == null) if (machine == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue; continue;
#endif
// Remove flagged items // Remove flagged items
if ((machine.GetBoolFieldValue(Models.Metadata.Machine.IsBiosKey) == true) if ((machine.GetBoolFieldValue(Models.Metadata.Machine.IsBiosKey) == true)
@@ -1039,7 +1054,11 @@ namespace SabreTools.DatFiles
{ {
RemoveBucket(bucket); RemoveBucket(bucket);
} }
#if NET40_OR_GREATER || NETCOREAPP
});
#else
} }
#endif
} }
/// <summary> /// <summary>
@@ -1052,17 +1071,32 @@ namespace SabreTools.DatFiles
private void RemoveBiosAndDeviceSetsImplDB() private void RemoveBiosAndDeviceSetsImplDB()
{ {
string[] buckets = [.. ItemsDB.SortedKeys]; string[] buckets = [.. ItemsDB.SortedKeys];
#if NET452_OR_GREATER || NETCOREAPP
Parallel.ForEach(buckets, Globals.ParallelOptions, bucket =>
#elif NET40_OR_GREATER
Parallel.ForEach(buckets, bucket =>
#else
foreach (string bucket in buckets) foreach (string bucket in buckets)
#endif
{ {
// If the bucket has no items in it // If the bucket has no items in it
Dictionary<long, DatItem> items = GetItemsForBucketDB(bucket); Dictionary<long, DatItem> items = GetItemsForBucketDB(bucket);
if (items.Count == 0) if (items.Count == 0)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue; continue;
#endif
// Get the machine // Get the machine
var machine = GetMachineForItemDB(items.First().Key); var machine = GetMachineForItemDB(items.First().Key);
if (machine.Value == null) if (machine.Value == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue; continue;
#endif
// Remove flagged items // Remove flagged items
if ((machine.Value.GetBoolFieldValue(Models.Metadata.Machine.IsBiosKey) == true) if ((machine.Value.GetBoolFieldValue(Models.Metadata.Machine.IsBiosKey) == true)
@@ -1076,7 +1110,11 @@ namespace SabreTools.DatFiles
// Remove the machine // Remove the machine
RemoveMachineDB(machine.Key); RemoveMachineDB(machine.Key);
#if NET40_OR_GREATER || NETCOREAPP
});
#else
} }
#endif
} }
/// <summary> /// <summary>