[Upstream] Performance optimizations based on discussion by recast4j #149

This commit is contained in:
ikpil 2023-07-21 14:35:45 +09:00
parent 9a4ed56eed
commit 971e07fde4
2 changed files with 10 additions and 12 deletions

View File

@ -3407,7 +3407,7 @@ namespace DotRecast.Detour
DtNode curNode = endNode;
do
{
path.Insert(0, curNode.id);
path.Add(curNode.id);
DtNode nextNode = m_nodePool.GetNodeAtIdx(curNode.pidx);
if (curNode.shortcut != null)
{
@ -3417,14 +3417,14 @@ namespace DotRecast.Detour
long id = curNode.shortcut[i];
if (id != curNode.id && id != nextNode.id)
{
path.Insert(0, id);
path.Add(id);
}
}
}
curNode = nextNode;
} while (curNode != null);
path.Reverse();
return DtStatus.DT_SUCCSESS;
}

View File

@ -74,23 +74,21 @@ namespace DotRecast.Detour
}
}
}
return Create(id, state);
else
{
nodes = new List<DtNode>();
m_map.Add(id, nodes);
}
protected DtNode Create(long id, int state)
return Create(id, state, nodes);
}
private DtNode Create(long id, int state, List<DtNode> nodes)
{
DtNode node = new DtNode(m_nodes.Count + 1);
node.id = id;
node.state = state;
m_nodes.Add(node);
var hasNode = m_map.TryGetValue(id, out var nodes);
;
if (nodes == null)
{
nodes = new List<DtNode>();
m_map.Add(id, nodes);
}
nodes.Add(node);
return node;