Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've reduced the number of array-lookups and did some tweaks in the function/method, which for me resulted in a speed-boost when recalculating the graph.
Using locals are quicker in LUA (link), than searching through a multi-dimensional-array, so that is why I replaced
self.ad.<member>
with anewPaths.<member>
, and reworked usage ofself.ad.Q[start][setToUse]
so there is no need to do multiple lookups.Also discovered that there is no need to make a deep-copy of the
Graph
intoQ
. An array of the 'unvisited' nodes will suffice, so that is why I've made a shallow-copy ofgraph
into localworkGraph
(previouslyQ
), which directly references the elements ingraph
, as these elements are not modified when this function is doing its task.Another trick with LUA, is that the indices of an array/table can have gaps - so it is actually not an 'array' as such. With this knowledge, I could see an optimization of the
for i2 in pairs(self.ad.Q) do ... if inQ == true then
, and changed it to do a direct-lookup if a wanted waypoint-id was still in theworkGraph
table (array).