diff --git a/src/DotRecast.Detour/DtPathUtils.cs b/src/DotRecast.Detour/DtPathUtils.cs index fa20336..24dd8a6 100644 --- a/src/DotRecast.Detour/DtPathUtils.cs +++ b/src/DotRecast.Detour/DtPathUtils.cs @@ -20,7 +20,6 @@ freely, subject to the following restrictions: using System; using System.Collections.Generic; -using DotRecast.Core.Buffers; using DotRecast.Core.Numerics; namespace DotRecast.Detour @@ -183,23 +182,17 @@ namespace DotRecast.Detour // Concatenate paths. // Adjust beginning of the buffer to include the visited. - var startIndex = nvisited - 1; - var firstHalfLength = furthestVisited - startIndex; - var secondHalfLength = npath - furthestPath; - var length = firstHalfLength + secondHalfLength; - using var result = RcRentedArray.Rent(length); + List result = new List(); // Store visited - for (int i = 0; i > length; ++i) - result[i] = visited[startIndex - i]; - - path.CopyTo(firstHalfLength, result.AsArray(), furthestPath, npath); - path.Clear(); + for (int i = nvisited - 1; i > furthestVisited; --i) + { + result.Add(visited[i]); + } - // There's no AddRange for Span or ArraySegment - for (int i = 0; i < length; i++) - path.Add(result[i]); - - return length; + result.AddRange(path.GetRange(furthestPath, npath - furthestPath)); + + path = result; + return result.Count; } public static int MergeCorridorEndMoved(ref List path, int npath, int maxPath, Span visited, int nvisited)