mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Handle some inefficiencies found via messages
This commit is contained in:
@@ -320,7 +320,7 @@ namespace SabreTools.DatFiles
|
||||
private void ConvertMachines(Models.Metadata.Machine[]? items, string filename, int indexId, bool statsOnly)
|
||||
{
|
||||
// If the array is invalid, we can't do anything
|
||||
if (items == null || !items.Any())
|
||||
if (items == null || items.Length == 0)
|
||||
return;
|
||||
|
||||
// Loop through the machines and add
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SabreTools.Core.Tools;
|
||||
@@ -15,7 +16,7 @@ namespace SabreTools.DatFiles
|
||||
public Models.Metadata.MetadataFile? ConvertMetadata(bool ignoreblanks = false)
|
||||
{
|
||||
// If we don't have items, we can't do anything
|
||||
if (this.Items == null || !this.Items.Any())
|
||||
if (Items == null || Items.Count == 0)
|
||||
return null;
|
||||
|
||||
// Create an object to hold the data
|
||||
@@ -212,7 +213,7 @@ namespace SabreTools.DatFiles
|
||||
foreach (string key in Items.SortedKeys)
|
||||
{
|
||||
var items = Items.FilteredItems(key);
|
||||
if (items == null || !items.Any())
|
||||
if (items == null || items.Count == 0)
|
||||
continue;
|
||||
|
||||
// Create a machine to hold everything
|
||||
@@ -436,7 +437,7 @@ namespace SabreTools.DatFiles
|
||||
}
|
||||
|
||||
// Handle Part, DiskItem, and DatItem mappings, if they exist
|
||||
if (partMappings.Any())
|
||||
if (partMappings.Count != 0)
|
||||
{
|
||||
// Create a collection to hold the inverted Parts
|
||||
Dictionary<string, Models.Metadata.Part> partItems = [];
|
||||
@@ -948,7 +949,11 @@ namespace SabreTools.DatFiles
|
||||
private static void EnsureMachineKey<T>(Models.Metadata.Machine machine, string key)
|
||||
{
|
||||
if (machine.Read<T[]?>(key) == null)
|
||||
#if NET20 || NET35 || NET40 || NET452
|
||||
machine[key] = new T[0];
|
||||
#else
|
||||
machine[key] = Array.Empty<T>();
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -983,6 +988,6 @@ namespace SabreTools.DatFiles
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -395,11 +395,11 @@ namespace SabreTools.DatFiles.Formats
|
||||
DatItem datItem = datItems[index];
|
||||
|
||||
// If we have a different game and we're not at the start of the list, output the end of last item
|
||||
if (lastgame != null && lastgame.ToLowerInvariant() != datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey)?.ToLowerInvariant())
|
||||
if (lastgame != null && !string.Equals(lastgame, datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey), StringComparison.OrdinalIgnoreCase))
|
||||
SabreJSON.WriteEndGame(jtw);
|
||||
|
||||
// If we have a new game, output the beginning of the new item
|
||||
if (lastgame == null || lastgame.ToLowerInvariant() != datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey)?.ToLowerInvariant())
|
||||
if (lastgame == null || !string.Equals(lastgame, datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey), StringComparison.OrdinalIgnoreCase))
|
||||
SabreJSON.WriteStartGame(jtw, datItem);
|
||||
|
||||
// Check for a "null" item
|
||||
|
||||
@@ -227,11 +227,11 @@ namespace SabreTools.DatFiles.Formats
|
||||
DatItem datItem = datItems[index];
|
||||
|
||||
// If we have a different game and we're not at the start of the list, output the end of last item
|
||||
if (lastgame != null && lastgame.ToLowerInvariant() != datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey)?.ToLowerInvariant())
|
||||
if (lastgame != null && !string.Equals(lastgame, datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey), StringComparison.OrdinalIgnoreCase))
|
||||
WriteEndGame(xtw);
|
||||
|
||||
// If we have a new game, output the beginning of the new item
|
||||
if (lastgame == null || lastgame.ToLowerInvariant() != datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey)?.ToLowerInvariant())
|
||||
if (lastgame == null || !string.Equals(lastgame, datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey), StringComparison.OrdinalIgnoreCase))
|
||||
WriteStartGame(xtw, datItem);
|
||||
|
||||
// Check for a "null" item
|
||||
|
||||
@@ -191,7 +191,7 @@ namespace SabreTools.DatFiles
|
||||
lock (key)
|
||||
{
|
||||
// If the value is null or empty, just return
|
||||
if (value == null || !value.Any())
|
||||
if (value == null || value.Count == 0)
|
||||
return;
|
||||
|
||||
// Ensure the key exists
|
||||
|
||||
@@ -430,7 +430,7 @@ namespace SabreTools.DatFiles
|
||||
private List<(long, DatItem)> Deduplicate(List<(long, DatItem)> itemMappings)
|
||||
{
|
||||
// Check for null or blank roms first
|
||||
if (itemMappings == null || !itemMappings.Any())
|
||||
if (itemMappings == null || itemMappings.Count == 0)
|
||||
return [];
|
||||
|
||||
// Create output list
|
||||
@@ -717,7 +717,7 @@ namespace SabreTools.DatFiles
|
||||
#endif
|
||||
{
|
||||
var itemIndices = _buckets[bucketKeys[i]];
|
||||
if (itemIndices == null || !itemIndices.Any())
|
||||
if (itemIndices == null || itemIndices.Count == 0)
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
return;
|
||||
#else
|
||||
@@ -760,7 +760,7 @@ namespace SabreTools.DatFiles
|
||||
#endif
|
||||
{
|
||||
var itemIndices = _buckets[bucketKeys[i]];
|
||||
if (itemIndices == null || !itemIndices.Any())
|
||||
if (itemIndices == null || itemIndices.Count == 0)
|
||||
{
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
_buckets.TryRemove(bucketKeys[i], out _);
|
||||
@@ -902,7 +902,7 @@ namespace SabreTools.DatFiles
|
||||
DatStatistics.ResetStatistics();
|
||||
|
||||
// If there are no items
|
||||
if (_items == null || !_items.Any())
|
||||
if (_items == null || _items.Count == 0)
|
||||
return;
|
||||
|
||||
// Loop through and add
|
||||
|
||||
Reference in New Issue
Block a user