From 6fe6844efdc880c5695136f24f349908e204c07d Mon Sep 17 00:00:00 2001 From: wrenge Date: Mon, 11 Nov 2024 14:26:35 +0300 Subject: [PATCH] Span access --- src/DotRecast.Core/Buffers/RcRentedArray.cs | 7 ++++++- src/DotRecast.Detour/DtNavMeshQuery.cs | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/DotRecast.Core/Buffers/RcRentedArray.cs b/src/DotRecast.Core/Buffers/RcRentedArray.cs index 68f12c7..208b951 100644 --- a/src/DotRecast.Core/Buffers/RcRentedArray.cs +++ b/src/DotRecast.Core/Buffers/RcRentedArray.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Buffers; using System.Runtime.CompilerServices; @@ -43,6 +43,11 @@ namespace DotRecast.Core.Buffers return _array; } + public Span AsSpan() + { + return new Span(_array, 0, Length); + } + public void Dispose() { diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index faeb460..e927024 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -599,7 +599,7 @@ namespace DotRecast.Detour const int batchSize = 32; Span polyRefs = stackalloc long[batchSize]; using RcRentedArray polysRent = RcRentedArray.Rent(batchSize); - Span polys = new Span(polysRent.AsArray(), 0, batchSize); + Span polys = polysRent.AsSpan(); int n = 0; if (tile.data.bvTree != null)