summaryrefslogtreecommitdiff
path: root/src/pathfinder.cpp
diff options
context:
space:
mode:
authorJozef Behran <jozuejozef@gmail.com>2019-01-12 10:57:26 -0500
committerLoïc Blot <nerzhul@users.noreply.github.com>2019-01-12 16:57:26 +0100
commit5a00b118959941722de977f2452f1e656c75304e (patch)
tree0a4a9d50514cd4f849cc60cbbf455732bc4a8f22 /src/pathfinder.cpp
parent03cc93f48957a5dee04c56ff8c5b05d647e77d2d (diff)
downloadminetest-5a00b118959941722de977f2452f1e656c75304e.tar.gz
minetest-5a00b118959941722de977f2452f1e656c75304e.tar.bz2
minetest-5a00b118959941722de977f2452f1e656c75304e.zip
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.
Diffstat (limited to 'src/pathfinder.cpp')
-rw-r--r--src/pathfinder.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/pathfinder.cpp b/src/pathfinder.cpp
index babdcff4e..8f6033813 100644
--- a/src/pathfinder.cpp
+++ b/src/pathfinder.cpp
@@ -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);
}