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;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using DotRecast.Core.Buffers;
|
||||||
using DotRecast.Core.Numerics;
|
using DotRecast.Core.Numerics;
|
||||||
|
|
||||||
namespace DotRecast.Detour
|
namespace DotRecast.Detour
|
||||||
|
@ -182,17 +183,23 @@ namespace DotRecast.Detour
|
||||||
// Concatenate paths.
|
// Concatenate paths.
|
||||||
|
|
||||||
// Adjust beginning of the buffer to include the visited.
|
// 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
|
// Store visited
|
||||||
for (int i = nvisited - 1; i > furthestVisited; --i)
|
for (int i = 0; i > length; ++i)
|
||||||
{
|
result[i] = visited[startIndex - i];
|
||||||
result.Add(visited[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
result.AddRange(path.GetRange(furthestPath, npath - furthestPath));
|
path.CopyTo(firstHalfLength, result.AsArray(), furthestPath, npath);
|
||||||
|
path.Clear();
|
||||||
|
|
||||||
path = result;
|
// There's no AddRange for Span or ArraySegment
|
||||||
return result.Count;
|
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)
|
public static int MergeCorridorEndMoved(ref List<long> path, int npath, int maxPath, Span<long> visited, int nvisited)
|
||||||
|
|
Loading…
Reference in New Issue