From 57533af15ea90b888ddb7f1defa69c3a73901b1b Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Tue, 2 Mar 2021 18:16:59 +0100 Subject: [PATCH] dnsdist: Use modern C++ loops in the packet cache code --- pdns/dnsdist-cache.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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; -- 2.47.2