Skip to content

Commit

Permalink
HashSet Add optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed Nov 14, 2024
1 parent c9f98e9 commit d3a61bf
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/Bannerlord.ModuleManager/ModuleUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -636,9 +636,8 @@ public static void EnableModule(IReadOnlyCollection<ModuleInfoExtended> modules,
}
private static void EnableModuleInternal(IReadOnlyCollection<ModuleInfoExtended> modules, ModuleInfoExtended targetModule, HashSet<ModuleInfoExtended> visitedModules, Func<ModuleInfoExtended, bool> getSelected, Action<ModuleInfoExtended, bool> setSelected, Func<ModuleInfoExtended, bool> getDisabled, Action<ModuleInfoExtended, bool> 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 };
Expand Down Expand Up @@ -709,9 +708,8 @@ public static void DisableModule(IReadOnlyCollection<ModuleInfoExtended> modules
}
private static void DisableModuleInternal(IReadOnlyCollection<ModuleInfoExtended> modules, ModuleInfoExtended targetModule, HashSet<ModuleInfoExtended> visitedModules, Func<ModuleInfoExtended, bool> getSelected, Action<ModuleInfoExtended, bool> setSelected, Func<ModuleInfoExtended, bool> getDisabled, Action<ModuleInfoExtended, bool> 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 };
Expand Down

0 comments on commit d3a61bf

Please sign in to comment.