From a7b9b772c4cc308cf3c2179001a18ef1b52eab39 Mon Sep 17 00:00:00 2001 From: wrenge Date: Tue, 12 Nov 2024 11:18:14 +0300 Subject: [PATCH] Use rented array instead of allocating (cherry picked from commit ff930712ee2c806753f39b7565f50e03a988691f) --- src/DotRecast.Detour/DtNavMesh.cs | 5 +++++ src/DotRecast.Detour/DtNavMeshQuery.cs | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/DotRecast.Detour/DtNavMesh.cs b/src/DotRecast.Detour/DtNavMesh.cs index a479123..54a2db3 100644 --- a/src/DotRecast.Detour/DtNavMesh.cs +++ b/src/DotRecast.Detour/DtNavMesh.cs @@ -1365,6 +1365,11 @@ namespace DotRecast.Detour } public int GetTilesAt(int x, int y, DtMeshTile[] tiles, int maxTiles) + { + return GetTilesAt(x, y, (Span)tiles, maxTiles); + } + + public int GetTilesAt(int x, int y, Span tiles, int maxTiles) { int n = 0; diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index 7200a57..4c636e5 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -797,7 +797,8 @@ namespace DotRecast.Detour m_nav.CalcTileLoc(bmax, out var maxx, out var maxy); const int MAX_NEIS = 32; - DtMeshTile[] neis = new DtMeshTile[MAX_NEIS]; + using RcRentedArray neisRent = RcRentedArray.Rent(MAX_NEIS); + Span neis = neisRent.AsSpan(); for (int y = miny; y <= maxy; ++y) {