From ccbb0dc04e07cde5c87defd5f6200eeb85a590d6 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 13 Jan 2025 21:57:08 -0500 Subject: [PATCH] Slight performance tweaks to mapping creation --- SabreTools.DatFiles/DatFile.Filtering.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/SabreTools.DatFiles/DatFile.Filtering.cs b/SabreTools.DatFiles/DatFile.Filtering.cs index 9862a5d7..b92bbf7c 100644 --- a/SabreTools.DatFiles/DatFile.Filtering.cs +++ b/SabreTools.DatFiles/DatFile.Filtering.cs @@ -120,11 +120,17 @@ namespace SabreTools.DatFiles if (machineName == null || machineDesc == null) continue; + // Adjust the description + machineDesc = machineDesc.Replace('/', '_').Replace("\"", "''").Replace(":", " -"); + if (machineName == machineDesc) + continue; + // If the key mapping doesn't exist, add it #if NET40_OR_GREATER || NETCOREAPP - mapping.TryAdd(machineName, machineDesc.Replace('/', '_').Replace("\"", "''").Replace(":", " -")); + mapping.TryAdd(machineName, machineDesc); #else - mapping[machineName] = machineDesc.Replace('/', '_').Replace("\"", "''").Replace(":", " -"); + if (!mapping.ContainsKey(machineName)) + mapping[machineName] = machineDesc; #endif } #if NET40_OR_GREATER || NETCOREAPP @@ -155,8 +161,14 @@ namespace SabreTools.DatFiles if (machineName == null || machineDesc == null) continue; + // Adjust the description + machineDesc = machineDesc.Replace('/', '_').Replace("\"", "''").Replace(":", " -"); + if (machineName == machineDesc) + continue; + // If the key mapping doesn't exist, add it - mapping[machineName] = machineDesc.Replace('/', '_').Replace("\"", "''").Replace(":", " -"); + if (!mapping.ContainsKey(machineName)) + mapping[machineName] = machineDesc; } return mapping;