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.
This commit is contained in:
RoosterDragon
2023-06-11 20:22:24 +01:00
committed by abcdefg30
parent fd2b14f464
commit 366dc5383c

View File

@@ -350,6 +350,7 @@ namespace OpenRA.Mods.Common.Pathfinder
? (Func<CPos, int>)null
: c => cellsWithBlockingActor.Contains(c) ? PathGraph.PathCostForInvalidPath : 0;
var accessibleCells = new HashSet<CPos>(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<CPos>();
for (var y = gridY; y < grid.BottomRight.Y; y++)
{
for (var x = gridX; x < grid.BottomRight.X; x++)