From bea43d38f4be4585ac57a0f40dd84a19843b3ddd Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 14 Jan 2025 20:48:07 -0500 Subject: [PATCH] Reduce unncessary DB methods --- SabreTools.DatFiles/DatFileTool.cs | 30 +++++++++---------------- SabreTools.DatFiles/ItemDictionaryDB.cs | 10 --------- SabreTools.DatTools/Splitter.cs | 24 +++++++------------- 3 files changed, 18 insertions(+), 46 deletions(-) diff --git a/SabreTools.DatFiles/DatFileTool.cs b/SabreTools.DatFiles/DatFileTool.cs index e76d01a0..085fc6db 100644 --- a/SabreTools.DatFiles/DatFileTool.cs +++ b/SabreTools.DatFiles/DatFileTool.cs @@ -938,8 +938,6 @@ namespace SabreTools.DatFiles var datItems = datFile.ItemsDB.GetItems(); var machines = datFile.GetMachinesDB(); var sources = datFile.ItemsDB.GetSources(); - var itemMachineMappings = datFile.ItemsDB.GetItemMachineMappings(); - var itemSourceMappings = datFile.ItemsDB.GetItemSourceMappings(); // Create mappings from old index to new index var machineRemapping = new Dictionary(); @@ -969,8 +967,8 @@ namespace SabreTools.DatFiles #endif { // Get the machine and source index for this item - long machineIndex = itemMachineMappings[item.Key]; - long sourceIndex = itemSourceMappings[item.Key]; + long machineIndex = datFile.ItemsDB.GetMachineForItem(item.Key).Key; + long sourceIndex = datFile.ItemsDB.GetSourceForItem(item.Key).Key; // If the current item isn't an external duplicate #if NET20 || NET35 @@ -1178,8 +1176,6 @@ namespace SabreTools.DatFiles var datItems = datFile.ItemsDB.GetItems(); var machines = datFile.GetMachinesDB(); var sources = datFile.ItemsDB.GetSources(); - var itemMachineMappings = datFile.ItemsDB.GetItemMachineMappings(); - var itemSourceMappings = datFile.ItemsDB.GetItemSourceMappings(); // Create mappings from old index to new index var machineRemapping = new Dictionary(); @@ -1219,8 +1215,8 @@ namespace SabreTools.DatFiles #endif { // Get the machine and source index for this item - long machineIndex = itemMachineMappings[item.Key]; - long sourceIndex = itemSourceMappings[item.Key]; + long machineIndex = datFile.ItemsDB.GetMachineForItem(item.Key).Key; + long sourceIndex = datFile.ItemsDB.GetSourceForItem(item.Key).Key; // Get the source associated with the item var source = datFile.ItemsDB.GetSource(sourceIndex); @@ -1371,8 +1367,6 @@ namespace SabreTools.DatFiles var datItems = datFile.ItemsDB.GetItems(); var machines = datFile.GetMachinesDB(); var sources = datFile.ItemsDB.GetSources(); - var itemMachineMappings = datFile.ItemsDB.GetItemMachineMappings(); - var itemSourceMappings = datFile.ItemsDB.GetItemSourceMappings(); // Create mappings from old index to new index var machineRemapping = new Dictionary(); @@ -1402,8 +1396,8 @@ namespace SabreTools.DatFiles #endif { // Get the machine and source index for this item - long machineIndex = itemMachineMappings[item.Key]; - long sourceIndex = itemSourceMappings[item.Key]; + long machineIndex = datFile.ItemsDB.GetMachineForItem(item.Key).Key; + long sourceIndex = datFile.ItemsDB.GetSourceForItem(item.Key).Key; // If the current item isn't a duplicate #if NET20 || NET35 @@ -1547,8 +1541,6 @@ namespace SabreTools.DatFiles var datItems = addFrom.ItemsDB.GetItems(); var machines = addFrom.GetMachinesDB(); var sources = addFrom.ItemsDB.GetSources(); - var itemMachineMappings = addFrom.ItemsDB.GetItemMachineMappings(); - var itemSourceMappings = addFrom.ItemsDB.GetItemSourceMappings(); // Create mappings from old index to new index var machineRemapping = new Dictionary(); @@ -1578,8 +1570,8 @@ namespace SabreTools.DatFiles #endif { // Get the machine and source index for this item - long machineIndex = itemMachineMappings[item.Key]; - long sourceIndex = itemSourceMappings[item.Key]; + long machineIndex = addFrom.ItemsDB.GetMachineForItem(item.Key).Key; + long sourceIndex = addFrom.ItemsDB.GetSourceForItem(item.Key).Key; addTo.AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false); @@ -1652,8 +1644,6 @@ namespace SabreTools.DatFiles var datItems = datFile.ItemsDB.GetItems(); var machines = datFile.GetMachinesDB(); var sources = datFile.ItemsDB.GetSources(); - var itemMachineMappings = datFile.ItemsDB.GetItemMachineMappings(); - var itemSourceMappings = datFile.ItemsDB.GetItemSourceMappings(); // Create mappings from old index to new index var machineRemapping = new Dictionary(); @@ -1683,8 +1673,8 @@ namespace SabreTools.DatFiles #endif { // Get the machine and source index for this item - long machineIndex = itemMachineMappings[item.Key]; - long sourceIndex = itemSourceMappings[item.Key]; + long machineIndex = datFile.ItemsDB.GetMachineForItem(item.Key).Key; + long sourceIndex = datFile.ItemsDB.GetSourceForItem(item.Key).Key; // Get the source associated with the item var source = datFile.ItemsDB.GetSource(sourceIndex); diff --git a/SabreTools.DatFiles/ItemDictionaryDB.cs b/SabreTools.DatFiles/ItemDictionaryDB.cs index 94312e94..700835cc 100644 --- a/SabreTools.DatFiles/ItemDictionaryDB.cs +++ b/SabreTools.DatFiles/ItemDictionaryDB.cs @@ -368,16 +368,6 @@ namespace SabreTools.DatFiles #endif } - /// - /// Get all item to machine mappings - /// - public IDictionary GetItemMachineMappings() => _itemToMachineMapping; - - /// - /// Get all item to source mappings - /// - public IDictionary GetItemSourceMappings() => _itemToSourceMapping; - /// /// Get all items and their indicies /// diff --git a/SabreTools.DatTools/Splitter.cs b/SabreTools.DatTools/Splitter.cs index 1b8ae73e..e5a43952 100644 --- a/SabreTools.DatTools/Splitter.cs +++ b/SabreTools.DatTools/Splitter.cs @@ -145,8 +145,6 @@ namespace SabreTools.DatTools var datItems = datFile.ItemsDB.GetItems(); var machines = datFile.GetMachinesDB(); var sources = datFile.ItemsDB.GetSources(); - var itemMachineMappings = datFile.ItemsDB.GetItemMachineMappings(); - var itemSourceMappings = datFile.ItemsDB.GetItemSourceMappings(); // Create mappings from old index to new index var machineRemapping = new Dictionary(); @@ -178,8 +176,8 @@ namespace SabreTools.DatTools #endif { // Get the machine and source index for this item - long machineIndex = itemMachineMappings[item.Key]; - long sourceIndex = itemSourceMappings[item.Key]; + long machineIndex = datFile.ItemsDB.GetMachineForItem(item.Key).Key; + long sourceIndex = datFile.ItemsDB.GetSourceForItem(item.Key).Key; if (newExtA.Contains((item.Value.GetName() ?? string.Empty).GetNormalizedExtension())) { @@ -361,8 +359,6 @@ namespace SabreTools.DatTools var datItems = datFile.ItemsDB.GetItems(); var machines = datFile.GetMachinesDB(); var sources = datFile.ItemsDB.GetSources(); - var itemMachineMappings = datFile.ItemsDB.GetItemMachineMappings(); - var itemSourceMappings = datFile.ItemsDB.GetItemSourceMappings(); // Create mappings from old index to new index var machineRemapping = new Dictionary(); @@ -410,8 +406,8 @@ namespace SabreTools.DatTools #endif { // Get the machine and source index for this item - long machineIndex = itemMachineMappings[item.Key]; - long sourceIndex = itemSourceMappings[item.Key]; + long machineIndex = datFile.ItemsDB.GetMachineForItem(item.Key).Key; + long sourceIndex = datFile.ItemsDB.GetSourceForItem(item.Key).Key; // Only process Disk, Media, and Rom switch (item.Value) @@ -699,8 +695,6 @@ namespace SabreTools.DatTools var datItems = datFile.ItemsDB.GetItems(); var machines = datFile.GetMachinesDB(); var sources = datFile.ItemsDB.GetSources(); - var itemMachineMappings = datFile.ItemsDB.GetItemMachineMappings(); - var itemSourceMappings = datFile.ItemsDB.GetItemSourceMappings(); // Create mappings from old index to new index var machineRemapping = new Dictionary(); @@ -732,8 +726,8 @@ namespace SabreTools.DatTools #endif { // Get the machine and source index for this item - long machineIndex = itemMachineMappings[item.Key]; - long sourceIndex = itemSourceMappings[item.Key]; + long machineIndex = datFile.ItemsDB.GetMachineForItem(item.Key).Key; + long sourceIndex = datFile.ItemsDB.GetSourceForItem(item.Key).Key; // If the file is not a Rom, it automatically goes in the "lesser" dat if (item.Value is not Rom rom) @@ -955,8 +949,6 @@ namespace SabreTools.DatTools var datItems = datFile.ItemsDB.GetItems(); var machines = datFile.GetMachinesDB(); var sources = datFile.ItemsDB.GetSources(); - var itemMachineMappings = datFile.ItemsDB.GetItemMachineMappings(); - var itemSourceMappings = datFile.ItemsDB.GetItemSourceMappings(); // Create mappings from old index to new index var machineRemapping = new Dictionary(); @@ -986,8 +978,8 @@ namespace SabreTools.DatTools #endif { // Get the machine and source index for this item - long machineIndex = itemMachineMappings[item.Key]; - long sourceIndex = itemSourceMappings[item.Key]; + long machineIndex = datFile.ItemsDB.GetMachineForItem(item.Key).Key; + long sourceIndex = datFile.ItemsDB.GetSourceForItem(item.Key).Key; if (item.Value.GetStringFieldValue(Models.Metadata.DatItem.TypeKey).AsEnumValue() == itemType) indexDat.AddItemDB(item.Value, machineRemapping[machineIndex], sourceRemapping[sourceIndex], statsOnly: false);