From 05613f196f56ed591959bc69b1fbe27721638f23 Mon Sep 17 00:00:00 2001 From: wrenge Date: Wed, 13 Nov 2024 12:52:33 +0300 Subject: [PATCH] MergeCorridorStartShortcut alloc fix --- src/DotRecast.Detour/DtPathUtils.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/DotRecast.Detour/DtPathUtils.cs b/src/DotRecast.Detour/DtPathUtils.cs index c58c353..f5e9d14 100644 --- a/src/DotRecast.Detour/DtPathUtils.cs +++ b/src/DotRecast.Detour/DtPathUtils.cs @@ -276,12 +276,15 @@ namespace DotRecast.Detour // Concatenate paths. // Adjust beginning of the buffer to include the visited. - List result = visited.GetRange(0, furthestVisited); - result.AddRange(path.GetRange(furthestPath, npath - furthestPath)); + var length1 = furthestVisited; + var length2 = npath - furthestPath; + using var result = RcRentedArray.Rent(length1 + length2); + visited.CopyTo(0, result.AsArray(), 0, length1); + path.CopyTo(furthestPath, result.AsArray(), length1, length2); path.Clear(); - path.AddRange(result); - return result.Count; + CollectionExtensions.AddRange(path, result.AsSpan()); + return result.Length; } } } \ No newline at end of file