Skip to content

Commit 5a00b11

Browse files
osjcnerzhul
authored andcommitted
Optimize path finalization in pathfinder (#8100)
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.
1 parent 03cc93f commit 5a00b11

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/pathfinder.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@ std::vector<v3s16> Pathfinder::getPath(ServerEnvironment *env,
707707

708708
//finalize path
709709
std::vector<v3s16> full_path;
710+
full_path.reserve(path.size());
710711
for (const v3s16 &i : path) {
711712
full_path.push_back(getIndexElement(i).pos);
712713
}

0 commit comments

Comments
 (0)