From a707f5fc96d4c42c64ae4aa7e614b8012f54c405 Mon Sep 17 00:00:00 2001 From: Uwe Seimet Date: Tue, 14 Jan 2025 00:18:34 +0100 Subject: [PATCH] Fix Sonar issues --- cpp/devices/disk_cache.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/cpp/devices/disk_cache.cpp b/cpp/devices/disk_cache.cpp index 8f084770..2f91b766 100644 --- a/cpp/devices/disk_cache.cpp +++ b/cpp/devices/disk_cache.cpp @@ -94,18 +94,16 @@ shared_ptr DiskCache::AssignTrack(int track) // Check for an empty cache slot for (CacheData &c : cache) { - if (!c.disktrk && Load(&c - &cache[0], track, nullptr)) { + if (!c.disktrk && Load(static_cast(&c - &cache[0]), track, nullptr)) { c.serial = serial; return c.disktrk; } } - // Find the cache entry with the smallest serial number, i.e. the oldest entry - auto c = min_element(cache.begin(), cache.end(), - [](const CacheData &d1, const CacheData &d2) {return d1.serial < d2.serial;}) - cache.begin(); - - // Save this track - if (cache[c].disktrk->Save(sec_path, cache_miss_write_count)) { + // Find the cache entry with the smallest serial number, i.e. the oldest entry and save this track + if (auto c = ranges::min_element(cache, + [](const CacheData &d1, const CacheData &d2) {return d1.serial < d2.serial;}) + - cache.begin(); cache[c].disktrk->Save(sec_path, cache_miss_write_count)) { // Delete this track auto disktrk = std::move(cache[c].disktrk);