Remove ContainsKey as it was really unneeded

This commit is contained in:
Matt Nadareski
2025-01-14 20:26:57 -05:00
parent 6e365c3f03
commit e05c6c35eb
3 changed files with 6 additions and 32 deletions

View File

@@ -538,10 +538,7 @@ namespace SabreTools.DatFiles
continue;
var list = datFile.GetItemsForBucket(key);
if (list.Count == 0)
continue;
if (datFile.Items.ContainsKey(key) && list.Count > 0)
if (list.Count > 0)
Replacer.ReplaceFields(newDatItem.GetFieldValue<Machine>(DatItem.MachineKey)!, list[index: 0].GetFieldValue<Machine>(DatItem.MachineKey)!, machineFieldNames, onlySame);
newDatItems.Add(newDatItem);

View File

@@ -247,24 +247,6 @@ namespace SabreTools.DatFiles
}
}
/// <summary>
/// Get if the file dictionary contains the key
/// </summary>
/// <param name="key">Key in the dictionary to check</param>
/// <returns>True if the key exists, false otherwise</returns>
public bool ContainsKey(string key)
{
// If the key is null, we return false since keys can't be null
if (key == null)
return false;
// Explicit lock for some weird corner cases
lock (key)
{
return _items.ContainsKey(key);
}
}
/// <summary>
/// Ensure the key exists in the items dictionary
/// </summary>
@@ -535,12 +517,11 @@ namespace SabreTools.DatFiles
// We want to get the proper key for the DatItem
string key = SortAndGetKey(datItem, sorted);
// If the key doesn't exist, return the empty list
if (!ContainsKey(key))
return false;
// Try to find duplicates
List<DatItem> roms = GetItemsForBucket(key);
if (roms.Count == 0)
return false;
return roms.FindIndex(r => datItem.Equals(r)) > -1;
}

View File

@@ -104,13 +104,9 @@ namespace SabreTools.DatTools
// Apply the mappings
foreach (string machine in machines)
{
// If the key doesn't exist, continue
if (!datFile.Items.ContainsKey(machine))
continue;
// Get the list of DatItems for the machine
var datItems = datFile.GetItemsForBucket(machine);
if (datItems == null)
List<DatItem> datItems = datFile.GetItemsForBucket(machine);
if (datItems.Count == 0)
continue;
// Try to get the map values, if possible