From: Remi Gacogne Date: Tue, 2 Mar 2021 17:16:59 +0000 (+0100) Subject: dnsdist: Use modern C++ loops in the packet cache code X-Git-Tag: dnsdist-1.6.0-alpha2~1^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=57533af15ea90b888ddb7f1defa69c3a73901b1b;p=thirdparty%2Fpdns.git dnsdist: Use modern C++ loops in the packet cache code --- diff --git a/pdns/dnsdist-cache.cc b/pdns/dnsdist-cache.cc index 88128e2465..8bb38c2ff7 100644 --- a/pdns/dnsdist-cache.cc +++ b/pdns/dnsdist-cache.cc @@ -45,8 +45,8 @@ DNSDistPacketCache::~DNSDistPacketCache() { try { vector> locks; - for (uint32_t shardIndex = 0; shardIndex < d_shardCount; shardIndex++) { - locks.push_back(std::unique_ptr(new WriteLock(&d_shards.at(shardIndex).d_lock))); + for (auto& shard : d_shards) { + locks.push_back(std::make_unique(&shard.d_lock)); } } catch(...) { @@ -403,8 +403,9 @@ uint64_t DNSDistPacketCache::getSize() { uint64_t count = 0; - for (uint32_t shardIndex = 0; shardIndex < d_shardCount; shardIndex++) { - count += d_shards.at(shardIndex).d_map.size(); + for (auto& shard : d_shards) { + ReadLock w(&shard.d_lock); + count += shard.d_map.size(); } return count; @@ -467,9 +468,9 @@ uint64_t DNSDistPacketCache::dump(int fd) uint64_t count = 0; time_t now = time(nullptr); - for (uint32_t shardIndex = 0; shardIndex < d_shardCount; shardIndex++) { - ReadLock w(&d_shards.at(shardIndex).d_lock); - auto& map = d_shards[shardIndex].d_map; + for (auto& shard : d_shards) { + ReadLock w(&shard.d_lock); + auto& map = shard.d_map; for (const auto& entry : map) { const CacheValue& value = entry.second;