diff --git a/.editorconfig b/.editorconfig index 2a1e9b280f..df08541619 100644 --- a/.editorconfig +++ b/.editorconfig @@ -866,6 +866,9 @@ dotnet_diagnostic.CA1865.severity = suggestion # TODO: Change to warning once us dotnet_diagnostic.CA1866.severity = suggestion # TODO: Change to warning once using .NET 8 or later. dotnet_diagnostic.CA1867.severity = suggestion # TODO: Change to warning once using .NET 8 or later. +# Unnecessary call to 'Contains' for sets. +dotnet_diagnostic.CA1868.severity = suggestion # TODO: Change to warning once using .NET 8 or later. + # Cache and reuse 'JsonSerializerOptions' instances. dotnet_diagnostic.CA1869.severity = suggestion # TODO: Change to warning once using .NET 8 or later. diff --git a/OpenRA.Game/FileSystem/FileSystem.cs b/OpenRA.Game/FileSystem/FileSystem.cs index 74fd728216..f6518ee173 100644 --- a/OpenRA.Game/FileSystem/FileSystem.cs +++ b/OpenRA.Game/FileSystem/FileSystem.cs @@ -159,9 +159,7 @@ namespace OpenRA.FileSystem explicitMounts.Remove(key); // Mod packages aren't owned by us, so we shouldn't dispose them - if (modPackages.Contains(package)) - modPackages.Remove(package); - else + if (!modPackages.Remove(package)) package.Dispose(); } else diff --git a/OpenRA.Game/Traits/World/ScreenMap.cs b/OpenRA.Game/Traits/World/ScreenMap.cs index 34a445846f..46e3c2b092 100644 --- a/OpenRA.Game/Traits/World/ScreenMap.cs +++ b/OpenRA.Game/Traits/World/ScreenMap.cs @@ -85,8 +85,7 @@ namespace OpenRA.Traits public void AddOrUpdate(Player viewer, FrozenActor fa) { - if (removeFrozenActors[viewer].Contains(fa)) - removeFrozenActors[viewer].Remove(fa); + removeFrozenActors[viewer].Remove(fa); addOrUpdateFrozenActors[viewer].Add(fa); } @@ -98,8 +97,7 @@ namespace OpenRA.Traits public void AddOrUpdate(Actor a) { - if (removeActors.Contains(a)) - removeActors.Remove(a); + removeActors.Remove(a); addOrUpdateActors.Add(a); } diff --git a/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs b/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs index 0d701607d8..8a8097f151 100644 --- a/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs +++ b/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs @@ -1163,9 +1163,7 @@ namespace OpenRA.Mods.Common.Server // Clearing an empty spawn point prevents it from being selected // Clearing a disabled spawn restores it for use - if (!server.LobbyInfo.DisabledSpawnPoints.Contains(spawnPoint)) - server.LobbyInfo.DisabledSpawnPoints.Add(spawnPoint); - else + if (!server.LobbyInfo.DisabledSpawnPoints.Add(spawnPoint)) server.LobbyInfo.DisabledSpawnPoints.Remove(spawnPoint); server.SyncLobbyInfo(); diff --git a/OpenRA.Mods.Common/Traits/DockHost.cs b/OpenRA.Mods.Common/Traits/DockHost.cs index 2c00b156f1..24f0460aa6 100644 --- a/OpenRA.Mods.Common/Traits/DockHost.cs +++ b/OpenRA.Mods.Common/Traits/DockHost.cs @@ -104,11 +104,8 @@ namespace OpenRA.Mods.Common.Traits public virtual void Unreserve(DockClientManager client) { - if (ReservedDockClients.Contains(client)) - { - ReservedDockClients.Remove(client); + if (ReservedDockClients.Remove(client)) client.UnreserveHost(); - } } public virtual void OnDockStarted(Actor self, Actor clientActor, DockClientManager client)