From ff930712ee2c806753f39b7565f50e03a988691f 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 --- 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 e927024..112c1fe 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -788,7 +788,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) {