Make SortedKeys an array for both

This commit is contained in:
Matt Nadareski
2025-01-14 15:59:47 -05:00
parent 616aea983b
commit 60d946fc6d
10 changed files with 38 additions and 82 deletions

View File

@@ -191,13 +191,12 @@ namespace SabreTools.DatFiles
/// <remarks>Applies to <see cref="Items"/></remarks>
private void ExecuteFiltersImpl(FilterRunner filterRunner)
{
List<string> keys = [.. Items.SortedKeys];
#if NET452_OR_GREATER || NETCOREAPP
Parallel.ForEach(keys, Core.Globals.ParallelOptions, key =>
Parallel.ForEach(Items.SortedKeys, Core.Globals.ParallelOptions, key =>
#elif NET40_OR_GREATER
Parallel.ForEach(keys, key =>
Parallel.ForEach(Items.SortedKeys, key =>
#else
foreach (var key in keys)
foreach (var key in Items.SortedKeys)
#endif
{
ExecuteFilterOnBucket(filterRunner, key);

View File

@@ -240,10 +240,7 @@ namespace SabreTools.DatFiles
/// </remarks>
private void AddItemsFromChildrenImpl(bool subfolder, bool skipDedup)
{
List<string> buckets = [.. Items.SortedKeys];
buckets.Sort();
foreach (string bucket in buckets)
foreach (string bucket in Items.SortedKeys)
{
// If the bucket has no items in it
List<DatItem> items = GetItemsForBucket(bucket);
@@ -503,10 +500,7 @@ namespace SabreTools.DatFiles
/// </remarks>
private void AddItemsFromCloneOfParentImpl()
{
List<string> buckets = [.. Items.SortedKeys];
buckets.Sort();
foreach (string bucket in buckets)
foreach (string bucket in Items.SortedKeys)
{
// If the bucket has no items in it
List<DatItem> items = GetItemsForBucket(bucket);
@@ -625,10 +619,7 @@ namespace SabreTools.DatFiles
private bool AddItemsFromDevicesImpl(bool deviceOnly, bool useSlotOptions)
{
bool foundnew = false;
List<string> buckets = [.. Items.SortedKeys];
buckets.Sort();
foreach (string bucket in buckets)
foreach (string bucket in Items.SortedKeys)
{
// If the bucket doesn't have items
List<DatItem> datItems = GetItemsForBucket(bucket);
@@ -937,10 +928,7 @@ namespace SabreTools.DatFiles
/// </remarks>
private void AddItemsFromRomOfParentImpl()
{
List<string> buckets = [.. Items.SortedKeys];
buckets.Sort();
foreach (string bucket in buckets)
foreach (string bucket in Items.SortedKeys)
{
// If the bucket has no items in it
List<DatItem> items = GetItemsForBucket(bucket);
@@ -1023,10 +1011,7 @@ namespace SabreTools.DatFiles
/// </remarks>
private void RemoveBiosAndDeviceSetsImpl()
{
List<string> buckets = [.. Items.SortedKeys];
buckets.Sort();
foreach (string bucket in buckets)
foreach (string bucket in Items.SortedKeys)
{
// If the bucket has no items in it
List<DatItem> items = GetItemsForBucket(bucket);
@@ -1093,10 +1078,7 @@ namespace SabreTools.DatFiles
/// </remarks>
private void RemoveItemsFromCloneOfChildImpl()
{
List<string> buckets = [.. Items.SortedKeys];
buckets.Sort();
foreach (string bucket in buckets)
foreach (string bucket in Items.SortedKeys)
{
// If the bucket has no items in it
List<DatItem> items = GetItemsForBucket(bucket);
@@ -1200,10 +1182,7 @@ namespace SabreTools.DatFiles
private void RemoveItemsFromRomOfChildImpl()
{
// Loop through the romof tags
List<string> buckets = [.. Items.SortedKeys];
buckets.Sort();
foreach (string bucket in buckets)
foreach (string bucket in Items.SortedKeys)
{
// If the bucket has no items in it
List<DatItem> items = GetItemsForBucket(bucket);
@@ -1281,10 +1260,7 @@ namespace SabreTools.DatFiles
/// <remarks>Applies to <see cref="Items"/></remarks>
private void RemoveMachineRelationshipTagsImpl()
{
List<string> buckets = [.. Items.SortedKeys];
buckets.Sort();
foreach (string bucket in buckets)
foreach (string bucket in Items.SortedKeys)
{
// If the bucket has no items in it
var items = GetItemsForBucket(bucket);

View File

@@ -311,13 +311,12 @@ namespace SabreTools.DatFiles
/// <param name="inputs">List of inputs to use for renaming</param>
public static void ApplySuperDAT(DatFile datFile, List<ParentablePath> inputs)
{
List<string> keys = [.. datFile.Items.SortedKeys];
#if NET452_OR_GREATER || NETCOREAPP
Parallel.ForEach(keys, Core.Globals.ParallelOptions, key =>
Parallel.ForEach(datFile.Items.SortedKeys, Core.Globals.ParallelOptions, key =>
#elif NET40_OR_GREATER
Parallel.ForEach(keys, key =>
Parallel.ForEach(datFile.Items.SortedKeys, key =>
#else
foreach (var key in keys)
foreach (var key in datFile.Items.SortedKeys)
#endif
{
List<DatItem>? items = datFile.GetItemsForBucket(key);
@@ -685,13 +684,12 @@ namespace SabreTools.DatFiles
intDat.BucketBy(ItemKey.CRC, DedupeType.Full);
// Then we compare against the base DAT
List<string> keys = [.. intDat.Items.SortedKeys];
#if NET452_OR_GREATER || NETCOREAPP
Parallel.ForEach(keys, Core.Globals.ParallelOptions, key =>
Parallel.ForEach(intDat.Items.SortedKeys, Core.Globals.ParallelOptions, key =>
#elif NET40_OR_GREATER
Parallel.ForEach(keys, key =>
Parallel.ForEach(intDat.Items.SortedKeys, key =>
#else
foreach (var key in keys)
foreach (var key in intDat.Items.SortedKeys)
#endif
{
// Game Against uses game names
@@ -1522,8 +1520,7 @@ namespace SabreTools.DatFiles
private static void AddFromExisting(DatFile addTo, DatFile addFrom, bool delete = false)
{
// Get the list of keys from the DAT
List<string> keys = [.. addFrom.Items.SortedKeys];
foreach (string key in keys)
foreach (string key in addFrom.Items.SortedKeys)
{
// Add everything from the key to the internal DAT
addFrom.GetItemsForBucket(key).ForEach(item => addTo.AddItem(item, statsOnly: false));

View File

@@ -50,29 +50,23 @@ namespace SabreTools.DatFiles
#endregion
#region Publically available fields
#region Keys
#region Fields
/// <summary>
/// Get the keys in sorted order from the file dictionary
/// </summary>
/// <returns>List of the keys in sorted order</returns>
[JsonIgnore, XmlIgnore]
public List<string> SortedKeys
public string[] SortedKeys
{
get
{
List<string> keys = [.. _items.Keys];
keys.Sort(new NaturalComparer());
return keys;
return [.. keys];
}
}
#endregion
#region Statistics
/// <summary>
/// DAT statistics
/// </summary>
@@ -81,8 +75,6 @@ namespace SabreTools.DatFiles
#endregion
#endregion
#region Constructors
/// <summary>
@@ -204,8 +196,7 @@ namespace SabreTools.DatFiles
/// </summary>
internal void ClearEmpty()
{
string[] keys = [.. SortedKeys];
foreach (string key in keys)
foreach (string key in SortedKeys)
{
#if NET40_OR_GREATER || NETCOREAPP
// If the key doesn't exist, skip
@@ -240,8 +231,7 @@ namespace SabreTools.DatFiles
/// </summary>
internal void ClearMarked()
{
string[] keys = [.. SortedKeys];
foreach (string key in keys)
foreach (string key in SortedKeys)
{
// Perform filtering on items
List<DatItem> list = GetItemsForBucket(key, filter: true);
@@ -664,13 +654,12 @@ namespace SabreTools.DatFiles
// Set the sorted type
_mergedBy = dedupeType;
List<string> keys = [.. SortedKeys];
#if NET452_OR_GREATER || NETCOREAPP
Parallel.ForEach(keys, Core.Globals.ParallelOptions, key =>
Parallel.ForEach(SortedKeys, Core.Globals.ParallelOptions, key =>
#elif NET40_OR_GREATER
Parallel.ForEach(keys, key =>
Parallel.ForEach(SortedKeys, key =>
#else
foreach (var key in keys)
foreach (var key in SortedKeys)
#endif
{
// Get the possibly unsorted list
@@ -698,13 +687,12 @@ namespace SabreTools.DatFiles
/// </summary>
private void PerformSorting()
{
List<string> keys = [.. SortedKeys];
#if NET452_OR_GREATER || NETCOREAPP
Parallel.ForEach(keys, Core.Globals.ParallelOptions, key =>
Parallel.ForEach(SortedKeys, Core.Globals.ParallelOptions, key =>
#elif NET40_OR_GREATER
Parallel.ForEach(keys, key =>
Parallel.ForEach(SortedKeys, key =>
#else
foreach (var key in keys)
foreach (var key in SortedKeys)
#endif
{
// Get the possibly unsorted list