From 46c035851a62c57cfa7889c3f1f039fb8105a289 Mon Sep 17 00:00:00 2001 From: Diogo Trindade Date: Wed, 11 Oct 2023 21:44:41 +0100 Subject: [PATCH] Core - Use StringComparison instead of ToUpper --- src/Artemis.Core/Plugins/Modules/DataModel.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Artemis.Core/Plugins/Modules/DataModel.cs b/src/Artemis.Core/Plugins/Modules/DataModel.cs index 880fffc4a..6d80e3b29 100644 --- a/src/Artemis.Core/Plugins/Modules/DataModel.cs +++ b/src/Artemis.Core/Plugins/Modules/DataModel.cs @@ -14,8 +14,9 @@ namespace Artemis.Core.Modules; /// public abstract class DataModel { + private const StringComparison PathsStringComparison = StringComparison.OrdinalIgnoreCase; private readonly List _activePaths = new(); - private readonly HashSet _activePathsHashSet = new(); + private readonly HashSet _activePathsHashSet = new(StringComparer.FromComparison(PathsStringComparison)); private readonly Dictionary _dynamicChildren = new(); /// @@ -332,11 +333,10 @@ public abstract class DataModel /// internal bool IsPropertyInUse(string path, bool includeChildren) { - path = path.ToUpperInvariant(); lock (_activePaths) { return includeChildren - ? _activePathsHashSet.Any(p => p.StartsWith(path, StringComparison.Ordinal)) + ? _activePathsHashSet.Any(p => p.StartsWith(path, PathsStringComparison)) : _activePathsHashSet.Contains(path); } } @@ -351,9 +351,7 @@ public abstract class DataModel _activePaths.Add(path); // Add to the hashset if this is the first path pointing - string hashPath = path.Path.ToUpperInvariant(); - if (!_activePathsHashSet.Contains(hashPath)) - _activePathsHashSet.Add(hashPath); + _activePathsHashSet.Add(path.Path); } OnActivePathAdded(new DataModelPathEventArgs(path)); @@ -368,7 +366,7 @@ public abstract class DataModel // Remove from the hashset if this was the last path pointing there if (_activePaths.All(p => p.Path != path.Path)) - _activePathsHashSet.Remove(path.Path.ToUpperInvariant()); + _activePathsHashSet.Remove(path.Path); } OnActivePathRemoved(new DataModelPathEventArgs(path));