Skip to content

Commit

Permalink
Optimize path finalization in pathfinder (minetest#8100)
Browse files Browse the repository at this point in the history
The pathfinder needs quite a bunch of items to add to the
resulting list. It turns out the amount of the space needed
for the finalized path is known in advance so preallocate it
to avoid a burst of reallocation calls each time something
needs to look for a path.
  • Loading branch information
osjc committed Jan 23, 2019
1 parent 820da1b commit 2d8f623
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/pathfinder.cpp
Expand Up @@ -707,6 +707,7 @@ std::vector<v3s16> Pathfinder::getPath(ServerEnvironment *env,

//finalize path
std::vector<v3s16> full_path;
full_path.reserve(path.size());
for (const v3s16 &i : path) {
full_path.push_back(getIndexElement(i).pos);
}
Expand Down

0 comments on commit 2d8f623

Please sign in to comment.