From a2ccfa22aa3f04484cba5dd8e58aeda51d518287 Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Wed, 9 Jul 2025 18:20:47 -0700 Subject: [DSC] Fix GetRegionAt / optimize GetRegionContaining `GetRegionAt` was really providing the semantics of `GetRegionContaining` due to `m_regions` being an `AddressRangeMap` and using transparent comparators to allow `find` to work with any address in the range. `GetRegionAt` is updated to verify that the start address of the region that was found matches the requested address. `GetRegionContaining` is updated to use `AddressRangeMap::find` rather than doing a linear search over all regions. --- view/sharedcache/core/SharedCache.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'view/sharedcache/core/SharedCache.cpp') diff --git a/view/sharedcache/core/SharedCache.cpp b/view/sharedcache/core/SharedCache.cpp index 0198ac48..c36c9ede 100644 --- a/view/sharedcache/core/SharedCache.cpp +++ b/view/sharedcache/core/SharedCache.cpp @@ -488,17 +488,17 @@ std::optional SharedCache::GetEntryWithImage(const CacheImage& image std::optional SharedCache::GetRegionAt(const uint64_t address) const { const auto it = m_regions.find(address); - if (it == m_regions.end()) + if (it == m_regions.end() || it->second.start != address) return std::nullopt; return it->second; } std::optional SharedCache::GetRegionContaining(const uint64_t address) const { - for (const auto& [range, region] : m_regions) - if (address >= range.start && address < range.end) - return region; - return std::nullopt; + const auto it = m_regions.find(address); + if (it == m_regions.end()) + return std::nullopt; + return it->second; } std::optional SharedCache::GetImageAt(const uint64_t address) const -- cgit v1.3.1