Optimize path finalization in pathfinder (#8100)
authorJozef Behran <jozuejozef@gmail.com>
Sat, 12 Jan 2019 15:57:26 +0000 (10:57 -0500)
committerLoïc Blot <nerzhul@users.noreply.github.com>
Sat, 12 Jan 2019 15:57:26 +0000 (16:57 +0100)
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

index babdcff4e4c0c1cd416afe2c610d99626b4f087d..8f60338139358134127e05af6b8b38bdb784da08 100644 (file)
@@ -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);
                }