forked from mirror/DotRecast
Removed allocations from MergeCorridorStartMoved
This commit is contained in:
parent
2c6f6a50cc
commit
49da3fb454
|
@ -20,7 +20,10 @@ 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.Collections;
|
||||||
using DotRecast.Core.Numerics;
|
using DotRecast.Core.Numerics;
|
||||||
|
using CollectionExtensions = DotRecast.Core.Collections.CollectionExtensions;
|
||||||
|
|
||||||
namespace DotRecast.Detour
|
namespace DotRecast.Detour
|
||||||
{
|
{
|
||||||
|
@ -180,20 +183,20 @@ namespace DotRecast.Detour
|
||||||
}
|
}
|
||||||
|
|
||||||
// Concatenate paths.
|
// Concatenate paths.
|
||||||
|
var endIndex = nvisited - 1;
|
||||||
|
var length1 = endIndex - furthestVisited;
|
||||||
|
var length2 = npath - furthestPath;
|
||||||
|
using var result = RcRentedArray.Rent<long>(length1 + length2);
|
||||||
// Adjust beginning of the buffer to include the visited.
|
// Adjust beginning of the buffer to include the visited.
|
||||||
List<long> result = new List<long>();
|
|
||||||
// Store visited
|
// Store visited
|
||||||
for (int i = nvisited - 1; i > furthestVisited; --i)
|
for (int i = 0; i < length1; ++i)
|
||||||
{
|
result[i] = visited[endIndex - i];
|
||||||
result.Add(visited[i]);
|
|
||||||
}
|
path.CopyTo(furthestPath, result.AsArray(), length1, length2);
|
||||||
|
|
||||||
result.AddRange(path.GetRange(furthestPath, npath - furthestPath));
|
|
||||||
|
|
||||||
path.Clear();
|
path.Clear();
|
||||||
path.AddRange(result);
|
CollectionExtensions.AddRange(path, result.AsSpan());
|
||||||
return result.Count;
|
return result.Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int MergeCorridorEndMoved(List<long> path, int npath, int maxPath, Span<long> visited, int nvisited)
|
public static int MergeCorridorEndMoved(List<long> path, int npath, int maxPath, Span<long> visited, int nvisited)
|
||||||
|
|
Loading…
Reference in New Issue