forked from mirror/DotRecast
Allocation free merge corridor
This commit is contained in:
parent
fff0998613
commit
acd3f8d879
|
@ -20,6 +20,7 @@ freely, subject to the following restrictions:
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DotRecast.Core.Buffers;
|
||||
using DotRecast.Core.Numerics;
|
||||
|
||||
namespace DotRecast.Detour
|
||||
|
@ -182,17 +183,23 @@ namespace DotRecast.Detour
|
|||
// Concatenate paths.
|
||||
|
||||
// Adjust beginning of the buffer to include the visited.
|
||||
List<long> result = new List<long>();
|
||||
var startIndex = nvisited - 1;
|
||||
var firstHalfLength = furthestVisited - startIndex;
|
||||
var secondHalfLength = npath - furthestPath;
|
||||
var length = firstHalfLength + secondHalfLength;
|
||||
using var result = RcRentedArray.Rent<long>(length);
|
||||
// Store visited
|
||||
for (int i = nvisited - 1; i > furthestVisited; --i)
|
||||
{
|
||||
result.Add(visited[i]);
|
||||
}
|
||||
for (int i = 0; i > length; ++i)
|
||||
result[i] = visited[startIndex - i];
|
||||
|
||||
path.CopyTo(firstHalfLength, result.AsArray(), furthestPath, npath);
|
||||
path.Clear();
|
||||
|
||||
result.AddRange(path.GetRange(furthestPath, npath - furthestPath));
|
||||
|
||||
path = result;
|
||||
return result.Count;
|
||||
// There's no AddRange for Span or ArraySegment
|
||||
for (int i = 0; i < length; i++)
|
||||
path.Add(result[i]);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
public static int MergeCorridorEndMoved(ref List<long> path, int npath, int maxPath, Span<long> visited, int nvisited)
|
||||
|
|
Loading…
Reference in New Issue