From 627fd4e68b495709e3ce7e446e988e8d21c6ca69 Mon Sep 17 00:00:00 2001 From: Vapre Date: Thu, 15 Jul 2021 23:20:35 +0200 Subject: [PATCH] CellLayer.Index inline CPos.ToMPos. --- OpenRA.Game/Map/CellLayer.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/OpenRA.Game/Map/CellLayer.cs b/OpenRA.Game/Map/CellLayer.cs index 984a174abc..1680d8f33f 100644 --- a/OpenRA.Game/Map/CellLayer.cs +++ b/OpenRA.Game/Map/CellLayer.cs @@ -52,7 +52,15 @@ namespace OpenRA // Resolve an array index from cell coordinates int Index(CPos cell) { - return Index(cell.ToMPos(GridType)); + // PERF: Inline CPos.ToMPos to avoid MPos allocation + var x = cell.X; + var y = cell.Y; + if (GridType == MapGridType.Rectangular) + return y * Size.Width + x; + + var u = (x - y) / 2; + var v = x + y; + return v * Size.Width + u; } // Resolve an array index from map coordinates