diff --git a/OpenRA.Mods.Cnc/UtilityCommands/LegacyTilesetImporter.cs b/OpenRA.Mods.Cnc/UtilityCommands/LegacyTilesetImporter.cs index efd3391958..f9d9dc5dbe 100644 --- a/OpenRA.Mods.Cnc/UtilityCommands/LegacyTilesetImporter.cs +++ b/OpenRA.Mods.Cnc/UtilityCommands/LegacyTilesetImporter.cs @@ -168,8 +168,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands metadata.AppendLine(); metadata.AppendLine("Terrain:"); - terrainTypes = terrainTypes.Distinct().ToArray(); - foreach (var terrainType in terrainTypes) + foreach (var terrainType in terrainTypes.Distinct()) { metadata.AppendLine($"\tTerrainType@{terrainType}:"); metadata.AppendLine($"\t\tType: {terrainType}"); diff --git a/OpenRA.Mods.Common/Scripting/Properties/ProductionProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/ProductionProperties.cs index 9ff58430cf..42c0777550 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/ProductionProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/ProductionProperties.cs @@ -244,8 +244,8 @@ namespace OpenRA.Mods.Common.Scripting foreach (var actorType in actorTypes.Distinct()) typeToQueueMap.Add(actorType, GetBuildableInfo(actorType).Queue.First()); - var queueTypes = typeToQueueMap.Values.Distinct().ToList(); - + // PERF: queues tend to live for a long time so cast to array. + var queueTypes = typeToQueueMap.Values.Distinct().ToArray(); if (queueTypes.Any(t => !queues.ContainsKey(t) || productionHandlers.ContainsKey(t))) return false; diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/GrantExternalConditionPower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/GrantExternalConditionPower.cs index d8bf57bd68..bc2cc971a9 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/GrantExternalConditionPower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/GrantExternalConditionPower.cs @@ -96,11 +96,12 @@ namespace OpenRA.Mods.Common.Traits public IEnumerable UnitsInRange(CPos xy) { var tiles = CellsMatching(xy, footprint, info.Dimensions); - var units = new List(); + var units = new HashSet(); foreach (var t in tiles) - units.AddRange(Self.World.ActorMap.GetActorsAt(t)); + foreach (var a in Self.World.ActorMap.GetActorsAt(t)) + units.Add(a); - return units.Distinct().Where(a => + return units.Where(a => { if (!info.ValidRelationships.HasRelationship(Self.Owner.RelationshipWith(a.Owner))) return false; diff --git a/OpenRA.Mods.Common/UtilityCommands/ExtractEmmyLuaAPI.cs b/OpenRA.Mods.Common/UtilityCommands/ExtractEmmyLuaAPI.cs index f438942474..e6e35ac7e0 100644 --- a/OpenRA.Mods.Common/UtilityCommands/ExtractEmmyLuaAPI.cs +++ b/OpenRA.Mods.Common/UtilityCommands/ExtractEmmyLuaAPI.cs @@ -128,7 +128,7 @@ namespace OpenRA.Mods.Common.UtilityCommands Console.WriteLine("---A list of ActorInit implementations that can be used by Lua scripts."); Console.WriteLine("---@class initTable"); - var localEnums = new List(); + var localEnums = new HashSet(); foreach (var init in actorInits) { var name = init.Name[..^4]; @@ -159,7 +159,7 @@ namespace OpenRA.Mods.Common.UtilityCommands } } - usedEnums = localEnums.Distinct(); + usedEnums = localEnums; } static void WriteEnums(IEnumerable enumTypes) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentLogic.cs index 9fe0f02bef..ddf6ecb405 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentLogic.cs @@ -112,9 +112,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic requiredWidget.IsVisible = () => p.Value.Required; var sourceWidget = container.Get("SOURCE"); - var sourceTitles = p.Value.Sources.Select(s => sources[s].Title).Distinct().ToList(); - var sourceList = sourceTitles.JoinWith("\n"); - var isSourceAvailable = sourceTitles.Count != 0; + var sourceList = p.Value.Sources.Select(s => sources[s].Title).Distinct().JoinWith("\n"); + var isSourceAvailable = sourceList.Length != 0; sourceWidget.GetTooltipText = () => sourceList; sourceWidget.IsVisible = () => isSourceAvailable; diff --git a/OpenRA.Mods.D2k/Activities/SwallowActor.cs b/OpenRA.Mods.D2k/Activities/SwallowActor.cs index e0980a2bf2..fee76d9aca 100644 --- a/OpenRA.Mods.D2k/Activities/SwallowActor.cs +++ b/OpenRA.Mods.D2k/Activities/SwallowActor.cs @@ -76,7 +76,7 @@ namespace OpenRA.Mods.D2k.Activities positionable.SetPosition(self, targetLocation); var attackPosition = self.CenterPosition; - var affectedPlayers = targets.Select(x => x.Owner).Distinct().ToList(); + var affectedPlayers = targets.Select(x => x.Owner).ToHashSet(); Game.Sound.Play(SoundType.World, swallow.Info.WormAttackSound, self.CenterPosition); foreach (var player in affectedPlayers)