From a51909bb64811694773b6dd3abd791d3d78d85e6 Mon Sep 17 00:00:00 2001 From: Jozef Behran Date: Sun, 13 Jan 2019 09:11:47 -0500 Subject: Speed up the craft definition handling (#8097) The craft definition handling code that collects the names of the craftable nodes suffers from vector reallocation performance hits, slowing down instances with lots of crafting recipes (VanessaE's DreamBuilder and most public server some to my mind when thinking about this). As in each instance the size of the resulting vector is already known, add a reserve() call before the offending loops to allocate the needed chunk of memory within the result vector in one go, getting rid of the overhead. --- src/craftdef.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/craftdef.cpp b/src/craftdef.cpp index d64b7e55e..077d7e044 100644 --- a/src/craftdef.cpp +++ b/src/craftdef.cpp @@ -112,6 +112,7 @@ static std::vector craftGetItemNames( const std::vector &itemstrings, IGameDef *gamedef) { std::vector result; + result.reserve(itemstrings.size()); for (const auto &itemstring : itemstrings) { result.push_back(craftGetItemName(itemstring, gamedef)); } @@ -123,6 +124,7 @@ static std::vector craftGetItemNames( const std::vector &items, IGameDef *gamedef) { std::vector result; + result.reserve(items.size()); for (const auto &item : items) { result.push_back(item.name); } @@ -134,6 +136,7 @@ static std::vector craftGetItems( const std::vector &items, IGameDef *gamedef) { std::vector result; + result.reserve(items.size()); for (const auto &item : items) { result.emplace_back(std::string(item), (u16)1, (u16)0, gamedef->getItemDefManager()); -- cgit v1.2.3