From 2a62f7f2a6e53313e9e8a3662c67de3ecbd964fd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Wed, 5 Feb 2025 18:22:53 +0100 Subject: [PATCH] Reserve room in loggers vector before adding loggers --- pdns/dnsdistdist/dnsdist-lua-bindings-protobuf.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 */ }); -- 2.47.2