From 418a39a576737373fbf463c1c2146ec8012404ee Mon Sep 17 00:00:00 2001 From: wrenge Date: Wed, 13 Nov 2024 12:57:19 +0300 Subject: [PATCH] MergeCorridorEndMoved alloc fix --- src/DotRecast.Detour/DtPathUtils.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/DotRecast.Detour/DtPathUtils.cs b/src/DotRecast.Detour/DtPathUtils.cs index f5e9d14..254b439 100644 --- a/src/DotRecast.Detour/DtPathUtils.cs +++ b/src/DotRecast.Detour/DtPathUtils.cs @@ -231,15 +231,15 @@ namespace DotRecast.Detour } // Concatenate paths. - List result = path.GetRange(0, furthestPath); - foreach (var v in visited.Slice(furthestVisited, nvisited - furthestVisited)) - { - result.Add(v); - } + var length1 = furthestPath; + var length2 = nvisited - furthestVisited; + using var result = RcRentedArray.Rent(length1 + length2); + path.CopyTo(0, result.AsArray(), 0, length1); + visited.Slice(furthestVisited, nvisited - furthestVisited).CopyTo(result.AsSpan().Slice(length1, length2)); path.Clear(); - path.AddRange(result); - return result.Count; + CollectionExtensions.AddRange(path, result.AsSpan()); + return path.Count; } public static int MergeCorridorStartShortcut(List path, int npath, int maxPath, List visited, int nvisited) @@ -284,7 +284,7 @@ namespace DotRecast.Detour path.Clear(); CollectionExtensions.AddRange(path, result.AsSpan()); - return result.Length; + return path.Count; } } } \ No newline at end of file