]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Reserve room in loggers vector before adding loggers
authorEnsar Sarajčić <dev@ensarsarajcic.com>
Wed, 5 Feb 2025 17:22:53 +0000 (18:22 +0100)
committerEnsar Sarajčić <dev@ensarsarajcic.com>
Wed, 5 Feb 2025 17:22:53 +0000 (18:22 +0100)
pdns/dnsdistdist/dnsdist-lua-bindings-protobuf.cc

index b5365a42e5cf7ae89311351f4a9ea60e8774ed9b..31fa8d1a0ae7c3cbb3f414c9edc4b2b7adef2237 100644 (file)
@@ -128,6 +128,7 @@ void setupLuaBindingsProtoBuf(LuaContext& luaCtx, bool client, bool configCheck)
     auto count = connectionCount ? *connectionCount : 1;
     if (count > 1) {
       std::vector<std::shared_ptr<RemoteLoggerInterface>> loggers;
+      loggers.reserve(count);
       for (uint64_t i = 0; i < count; i++) {
         loggers.push_back(std::make_shared<RemoteLogger>(ComboAddress(remote), timeout ? *timeout : 2, maxQueuedEntries ? (*maxQueuedEntries * 100) : 10000, reconnectWaitTime ? *reconnectWaitTime : 1, client));
       }
@@ -151,6 +152,7 @@ void setupLuaBindingsProtoBuf(LuaContext& luaCtx, bool client, bool configCheck)
     options.erase(connectionCount);
     if (count > 1) {
       std::vector<std::shared_ptr<RemoteLoggerInterface>> loggers;
+      loggers.reserve(count);
       for (uint64_t i = 0; i < count; i++) {
         loggers.push_back(std::make_shared<FrameStreamLogger>(AF_UNIX, address, !client, options));
       }
@@ -159,7 +161,7 @@ void setupLuaBindingsProtoBuf(LuaContext& luaCtx, bool client, bool configCheck)
 
     return std::shared_ptr<RemoteLoggerInterface>(new FrameStreamLogger(AF_UNIX, address, !client, options));
 #else
-      throw std::runtime_error("fstrm support is required to build an AF_UNIX FrameStreamLogger");
+    throw std::runtime_error("fstrm support is required to build an AF_UNIX FrameStreamLogger");
 #endif /* HAVE_FSTRM */
   });
 
@@ -177,6 +179,7 @@ void setupLuaBindingsProtoBuf(LuaContext& luaCtx, bool client, bool configCheck)
     options.erase(connectionCount);
     if (count > 1) {
       std::vector<std::shared_ptr<RemoteLoggerInterface>> loggers;
+      loggers.reserve(count);
       for (uint64_t i = 0; i < count; i++) {
         loggers.push_back(std::make_shared<FrameStreamLogger>(AF_INET, address, !client, options));
       }
@@ -185,7 +188,7 @@ void setupLuaBindingsProtoBuf(LuaContext& luaCtx, bool client, bool configCheck)
 
     return std::shared_ptr<RemoteLoggerInterface>(new FrameStreamLogger(AF_INET, address, !client, options));
 #else
-      throw std::runtime_error("fstrm with TCP support is required to build an AF_INET FrameStreamLogger");
+    throw std::runtime_error("fstrm with TCP support is required to build an AF_INET FrameStreamLogger");
 #endif /* HAVE_FSTRM */
   });