From d3a61bf71657824f7118c4e51c070d5c9a932509 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Thu, 14 Nov 2024 13:20:30 +0200 Subject: [PATCH] HashSet Add optimization --- src/Bannerlord.ModuleManager/ModuleUtilities.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Bannerlord.ModuleManager/ModuleUtilities.cs b/src/Bannerlord.ModuleManager/ModuleUtilities.cs index f02e7a8..2cb5e16 100644 --- a/src/Bannerlord.ModuleManager/ModuleUtilities.cs +++ b/src/Bannerlord.ModuleManager/ModuleUtilities.cs @@ -636,9 +636,8 @@ public static void EnableModule(IReadOnlyCollection modules, } private static void EnableModuleInternal(IReadOnlyCollection modules, ModuleInfoExtended targetModule, HashSet visitedModules, Func getSelected, Action setSelected, Func getDisabled, Action setDisabled) { - if (visitedModules.Contains(targetModule)) return; - visitedModules.Add(targetModule); - + if (!visitedModules.Add(targetModule)) return; + setSelected(targetModule, true); var opt = new ModuleSorterOptions { SkipOptionals = true, SkipExternalDependencies = true }; @@ -709,9 +708,8 @@ public static void DisableModule(IReadOnlyCollection modules } private static void DisableModuleInternal(IReadOnlyCollection modules, ModuleInfoExtended targetModule, HashSet visitedModules, Func getSelected, Action setSelected, Func getDisabled, Action setDisabled) { - if (visitedModules.Contains(targetModule)) return; - visitedModules.Add(targetModule); - + if (!visitedModules.Add(targetModule)) return; + setSelected(targetModule, false); var opt = new ModuleSorterOptions { SkipOptionals = true, SkipExternalDependencies = true };