| 176 | } |
| 177 | |
| 178 | void SharedCache::AddRegion(CacheRegion&& region) |
| 179 | { |
| 180 | // Handle overlapping regions here. |
| 181 | const auto regionRange = region.AsAddressRange(); |
| 182 | // First region at or past the start of the region. |
| 183 | const auto begin = m_regions.lower_bound(regionRange.start); |
| 184 | if (begin == m_regions.end()) |
| 185 | { |
| 186 | AddNonOverlappingRegion(std::move(region)); |
| 187 | return; |
| 188 | } |
| 189 | |
| 190 | // First region past the end of the region. |
| 191 | const auto end = m_regions.lower_bound(regionRange.end); |
| 192 | |
| 193 | for (auto it = begin; it != end; ++it) |
| 194 | { |
| 195 | const uint64_t newRegionSize = it->second.start - region.start; |
| 196 | if (newRegionSize) |
| 197 | { |
| 198 | CacheRegion newRegion(region); |
| 199 | newRegion.size = newRegionSize; |
| 200 | AddNonOverlappingRegion(std::move(newRegion)); |
| 201 | } |
| 202 | |
| 203 | region.start = it->second.start + it->second.size; |
| 204 | region.size -= (newRegionSize + it->second.size); |
| 205 | } |
| 206 | |
| 207 | // Add remaining region. |
| 208 | if (region.size > 0) |
| 209 | AddNonOverlappingRegion(std::move(region)); |
| 210 | } |
| 211 | |
| 212 | bool SharedCache::AddNonOverlappingRegion(CacheRegion region) |
| 213 | { |
nothing calls this directly
no test coverage detected