From 5a00b118959941722de977f2452f1e656c75304e Mon Sep 17 00:00:00 2001 From: Jozef Behran Date: Sat, 12 Jan 2019 10:57:26 -0500 Subject: [PATCH] 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. --- src/pathfinder.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pathfinder.cpp b/src/pathfinder.cpp index babdcff4..8f603381 100644 --- a/src/pathfinder.cpp +++ b/src/pathfinder.cpp @@ -707,6 +707,7 @@ std::vector Pathfinder::getPath(ServerEnvironment *env, //finalize path std::vector full_path; + full_path.reserve(path.size()); for (const v3s16 &i : path) { full_path.push_back(getIndexElement(i).pos); }