Use HashSets instead of .Distinct
And don't cast to array / list where unnecessary
This commit is contained in:
@@ -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}");
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -96,11 +96,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public IEnumerable<Actor> UnitsInRange(CPos xy)
|
||||
{
|
||||
var tiles = CellsMatching(xy, footprint, info.Dimensions);
|
||||
var units = new List<Actor>();
|
||||
var units = new HashSet<Actor>();
|
||||
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;
|
||||
|
||||
@@ -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<Type>();
|
||||
var localEnums = new HashSet<Type>();
|
||||
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<Type> enumTypes)
|
||||
|
||||
@@ -112,9 +112,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
requiredWidget.IsVisible = () => p.Value.Required;
|
||||
|
||||
var sourceWidget = container.Get<ImageWidget>("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;
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user