Skip to content

Commit

Permalink
Fix Sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Jan 13, 2025
1 parent fa78dcb commit a707f5f
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions cpp/devices/disk_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,16 @@ shared_ptr<DiskTrack> 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<int>(&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);

Expand Down

0 comments on commit a707f5f

Please sign in to comment.