From 366dc5383c406e27d613ec07fd0bbd68f71c24be Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Sun, 11 Jun 2023 20:22:24 +0100 Subject: [PATCH] In HierarchicalPathFinder.BuildGrid, presize and reuse accessible cell set. Most cells are accessible, so presizing to the full size of the grid is sensible to avoid allocations to resize as it is filled up. The set can also be reused across all layers to avoid allocating it many times. --- OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs b/OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs index e67fd9ecd3..9dcde2ad8f 100644 --- a/OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs +++ b/OpenRA.Mods.Common/Pathfinder/HierarchicalPathFinder.cs @@ -350,6 +350,7 @@ namespace OpenRA.Mods.Common.Pathfinder ? (Func)null : c => cellsWithBlockingActor.Contains(c) ? PathGraph.PathCostForInvalidPath : 0; + var accessibleCells = new HashSet(GridSize * GridSize); for (byte gridLayer = 0; gridLayer < customMovementLayers.Length; gridLayer++) { if (gridLayer != 0 && @@ -358,7 +359,6 @@ namespace OpenRA.Mods.Common.Pathfinder continue; var grid = GetGrid(new CPos(gridX, gridY, gridLayer), mapBounds); - var accessibleCells = new HashSet(); for (var y = gridY; y < grid.BottomRight.Y; y++) { for (var x = gridX; x < grid.BottomRight.X; x++)