From: Remi Gacogne Date: Thu, 15 Mar 2018 09:49:25 +0000 (+0100) Subject: dnsdist: Use a reserve()'d unordered_map for exceed* functions X-Git-Tag: dnsdist-1.3.0~49^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f83271250e7df637d544b98862341660c7376e3e;p=pdns dnsdist: Use a reserve()'d unordered_map for exceed* functions --- diff --git a/pdns/dnsdist-lua-inspection.cc b/pdns/dnsdist-lua-inspection.cc index e2c32cee4..c75d0bad4 100644 --- a/pdns/dnsdist-lua-inspection.cc +++ b/pdns/dnsdist-lua-inspection.cc @@ -75,19 +75,21 @@ static std::unordered_map>> g return ret; } -static void filterScore(map& counts, +typedef std::unordered_map counts_t; + +static counts_t filterScore(const counts_t& counts, double delta, unsigned int rate) { + counts_t ret; + double lim = delta*rate; - for(auto iter = counts.begin(); iter != counts.end();) { - if (iter->second <= lim) { - iter = counts.erase(iter); - } - else { - iter++; + for(const auto& c : counts) { + if (c.second > lim) { + ret[c.first] = c.second; } } + return ret; } @@ -140,7 +142,6 @@ static vector > > getRespRi return ret; } -typedef map counts_t; static counts_t exceedRespGen(unsigned int rate, int seconds, std::function T) { counts_t counts; @@ -151,6 +152,7 @@ static counts_t exceedRespGen(unsigned int rate, int seconds, std::function lock(g_rings.respMutex); + counts.reserve(g_rings.respRing.size()); for(const auto& c : g_rings.respRing) { if(seconds && c.when < cutoff) continue; @@ -164,8 +166,7 @@ static counts_t exceedRespGen(unsigned int rate, int seconds, std::function T) @@ -178,6 +179,7 @@ static counts_t exceedQueryGen(unsigned int rate, int seconds, std::function& m, const std::string& msg, boost::optional seconds, boost::optional action) { + [](const std::unordered_map& m, const std::string& msg, boost::optional seconds, boost::optional action) { setLuaSideEffect(); auto slow = g_dynblockNMG.getCopy(); struct timespec until, now;