1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 21:38:38 +00:00

Core - Use StringComparison instead of ToUpper

This commit is contained in:
Diogo Trindade 2023-10-11 21:44:41 +01:00
parent 38eb0ff460
commit 46c035851a

View File

@ -14,8 +14,9 @@ namespace Artemis.Core.Modules;
/// </summary> /// </summary>
public abstract class DataModel public abstract class DataModel
{ {
private const StringComparison PathsStringComparison = StringComparison.OrdinalIgnoreCase;
private readonly List<DataModelPath> _activePaths = new(); private readonly List<DataModelPath> _activePaths = new();
private readonly HashSet<string> _activePathsHashSet = new(); private readonly HashSet<string> _activePathsHashSet = new(StringComparer.FromComparison(PathsStringComparison));
private readonly Dictionary<string, DynamicChild> _dynamicChildren = new(); private readonly Dictionary<string, DynamicChild> _dynamicChildren = new();
/// <summary> /// <summary>
@ -332,11 +333,10 @@ public abstract class DataModel
/// </param> /// </param>
internal bool IsPropertyInUse(string path, bool includeChildren) internal bool IsPropertyInUse(string path, bool includeChildren)
{ {
path = path.ToUpperInvariant();
lock (_activePaths) lock (_activePaths)
{ {
return includeChildren return includeChildren
? _activePathsHashSet.Any(p => p.StartsWith(path, StringComparison.Ordinal)) ? _activePathsHashSet.Any(p => p.StartsWith(path, PathsStringComparison))
: _activePathsHashSet.Contains(path); : _activePathsHashSet.Contains(path);
} }
} }
@ -351,9 +351,7 @@ public abstract class DataModel
_activePaths.Add(path); _activePaths.Add(path);
// Add to the hashset if this is the first path pointing // Add to the hashset if this is the first path pointing
string hashPath = path.Path.ToUpperInvariant(); _activePathsHashSet.Add(path.Path);
if (!_activePathsHashSet.Contains(hashPath))
_activePathsHashSet.Add(hashPath);
} }
OnActivePathAdded(new DataModelPathEventArgs(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 // Remove from the hashset if this was the last path pointing there
if (_activePaths.All(p => p.Path != path.Path)) if (_activePaths.All(p => p.Path != path.Path))
_activePathsHashSet.Remove(path.Path.ToUpperInvariant()); _activePathsHashSet.Remove(path.Path);
} }
OnActivePathRemoved(new DataModelPathEventArgs(path)); OnActivePathRemoved(new DataModelPathEventArgs(path));