diff --git a/src/DotRecast.Core/RcSpans.cs b/src/DotRecast.Core/RcSpans.cs index 283defc..be7f832 100644 --- a/src/DotRecast.Core/RcSpans.cs +++ b/src/DotRecast.Core/RcSpans.cs @@ -26,5 +26,11 @@ namespace DotRecast.Core var slicedDst = src.Slice(dstIdx, length); slicedSrc.CopyTo(slicedDst); } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void Fill(Span span, T value, int start, int count) + { + span.Slice(start, count).Fill(value); + } } } \ No newline at end of file diff --git a/src/DotRecast.Detour.TileCache/DtTileCacheBuilder.cs b/src/DotRecast.Detour.TileCache/DtTileCacheBuilder.cs index 819ac9e..824f881 100644 --- a/src/DotRecast.Detour.TileCache/DtTileCacheBuilder.cs +++ b/src/DotRecast.Detour.TileCache/DtTileCacheBuilder.cs @@ -52,14 +52,14 @@ namespace DotRecast.Detour.TileCache } // Partition walkable area into monotone regions. - int[] prevCount = new int[256]; + Span prevCount = stackalloc byte[256]; byte regId = 0; for (int y = 0; y < h; ++y) { if (regId > 0) { - Array.Fill(prevCount, 0, 0, regId); + RcSpans.Fill(prevCount, 0, 0, regId); } // Memset(prevCount,0,Sizeof(char)*regId); @@ -225,7 +225,7 @@ namespace DotRecast.Detour.TileCache } // Compact ids. - byte[] remap = new byte[256]; + Span remap = stackalloc byte[256]; // Find number of unique regions. regId = 0; for (int i = 0; i < nregs; ++i)