From 858e094ea02187cc1153c3a8dbd761e371269a65 Mon Sep 17 00:00:00 2001 From: wrenge Date: Wed, 13 Nov 2024 11:11:12 +0300 Subject: [PATCH] Revert "Allocation free merge corridor" This reverts commit acd3f8d8792acaa87f398b63cc94c54feef1cdea. --- src/DotRecast.Detour/DtPathUtils.cs | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) 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)