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