From: Ensar Sarajčić Date: Wed, 5 Feb 2025 17:22:53 +0000 (+0100) Subject: Reserve room in loggers vector before adding loggers X-Git-Tag: dnsdist-2.0.0-alpha1~111^2~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a62f7f2a6e53313e9e8a3662c67de3ecbd964fd;p=thirdparty%2Fpdns.git Reserve room in loggers vector before adding loggers --- diff --git a/pdns/dnsdistdist/dnsdist-lua-bindings-protobuf.cc b/pdns/dnsdistdist/dnsdist-lua-bindings-protobuf.cc index b5365a42e5..31fa8d1a0a 100644 --- a/pdns/dnsdistdist/dnsdist-lua-bindings-protobuf.cc +++ b/pdns/dnsdistdist/dnsdist-lua-bindings-protobuf.cc @@ -128,6 +128,7 @@ void setupLuaBindingsProtoBuf(LuaContext& luaCtx, bool client, bool configCheck) auto count = connectionCount ? *connectionCount : 1; if (count > 1) { std::vector> loggers; + loggers.reserve(count); for (uint64_t i = 0; i < count; i++) { loggers.push_back(std::make_shared(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> loggers; + loggers.reserve(count); for (uint64_t i = 0; i < count; i++) { loggers.push_back(std::make_shared(AF_UNIX, address, !client, options)); } @@ -159,7 +161,7 @@ void setupLuaBindingsProtoBuf(LuaContext& luaCtx, bool client, bool configCheck) return std::shared_ptr(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> loggers; + loggers.reserve(count); for (uint64_t i = 0; i < count; i++) { loggers.push_back(std::make_shared(AF_INET, address, !client, options)); } @@ -185,7 +188,7 @@ void setupLuaBindingsProtoBuf(LuaContext& luaCtx, bool client, bool configCheck) return std::shared_ptr(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 */ });