Skip to content

Commit 0849147

Browse files
committed
[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.
1 parent f3e2a87 commit 0849147

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

view/sharedcache/core/SharedCache.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -488,17 +488,17 @@ std::optional<CacheEntry> SharedCache::GetEntryWithImage(const CacheImage& image
488488
std::optional<CacheRegion> SharedCache::GetRegionAt(const uint64_t address) const
489489
{
490490
const auto it = m_regions.find(address);
491-
if (it == m_regions.end())
491+
if (it == m_regions.end() || it->second.start != address)
492492
return std::nullopt;
493493
return it->second;
494494
}
495495

496496
std::optional<CacheRegion> SharedCache::GetRegionContaining(const uint64_t address) const
497497
{
498-
for (const auto& [range, region] : m_regions)
499-
if (address >= range.start && address < range.end)
500-
return region;
501-
return std::nullopt;
498+
const auto it = m_regions.find(address);
499+
if (it == m_regions.end())
500+
return std::nullopt;
501+
return it->second;
502502
}
503503

504504
std::optional<CacheImage> SharedCache::GetImageAt(const uint64_t address) const

0 commit comments

Comments
 (0)