diff options
| author | 2024-02-05 12:46:49 +0100 | |
|---|---|---|
| committer | 2024-02-05 23:01:17 +0100 | |
| commit | fa47ac1c9f8b117d556c7c18ac9dcb062af5cefc (patch) | |
| tree | e39eeaccfaa2c404f5c585b71606a421268254d0 /src/common/range_sets.inc | |
| parent | Buffer Cache: Refactor to use Range sets instead (diff) | |
| download | yuzu-fa47ac1c9f8b117d556c7c18ac9dcb062af5cefc.tar.gz yuzu-fa47ac1c9f8b117d556c7c18ac9dcb062af5cefc.tar.xz yuzu-fa47ac1c9f8b117d556c7c18ac9dcb062af5cefc.zip | |
Common: Rename SplitRangeSet to OverlapRangeSet
Diffstat (limited to '')
| -rw-r--r-- | src/common/range_sets.inc | 63 |
1 files changed, 33 insertions, 30 deletions
diff --git a/src/common/range_sets.inc b/src/common/range_sets.inc index 705ebd4a1..b83eceb7b 100644 --- a/src/common/range_sets.inc +++ b/src/common/range_sets.inc | |||
| @@ -19,14 +19,18 @@ | |||
| 19 | 19 | ||
| 20 | namespace Common { | 20 | namespace Common { |
| 21 | 21 | ||
| 22 | namespace { | ||
| 23 | template <class T> | ||
| 24 | using RangeSetsAllocator = | ||
| 25 | boost::fast_pool_allocator<T, boost::default_user_allocator_new_delete, | ||
| 26 | boost::details::pool::default_mutex, 1024, 2048>; | ||
| 27 | } | ||
| 28 | |||
| 22 | template <typename AddressType> | 29 | template <typename AddressType> |
| 23 | struct RangeSet<AddressType>::RangeSetImpl { | 30 | struct RangeSet<AddressType>::RangeSetImpl { |
| 24 | template <class T> | ||
| 25 | using MyAllocator = boost::fast_pool_allocator<T, boost::default_user_allocator_new_delete, | ||
| 26 | boost::details::pool::default_mutex, 1024, 2048>; | ||
| 27 | using IntervalSet = boost::icl::interval_set< | 31 | using IntervalSet = boost::icl::interval_set< |
| 28 | AddressType, std::less, ICL_INTERVAL_INSTANCE(ICL_INTERVAL_DEFAULT, AddressType, std::less), | 32 | AddressType, std::less, ICL_INTERVAL_INSTANCE(ICL_INTERVAL_DEFAULT, AddressType, std::less), |
| 29 | MyAllocator>; | 33 | RangeSetsAllocator>; |
| 30 | using IntervalType = typename IntervalSet::interval_type; | 34 | using IntervalType = typename IntervalSet::interval_type; |
| 31 | 35 | ||
| 32 | RangeSetImpl() = default; | 36 | RangeSetImpl() = default; |
| @@ -88,18 +92,15 @@ struct RangeSet<AddressType>::RangeSetImpl { | |||
| 88 | }; | 92 | }; |
| 89 | 93 | ||
| 90 | template <typename AddressType> | 94 | template <typename AddressType> |
| 91 | struct SplitRangeSet<AddressType>::SplitRangeSetImpl { | 95 | struct OverlapRangeSet<AddressType>::OverlapRangeSetImpl { |
| 92 | template <class T> | ||
| 93 | using MyAllocator = boost::fast_pool_allocator<T, boost::default_user_allocator_new_delete, | ||
| 94 | boost::details::pool::default_mutex, 1024, 2048>; | ||
| 95 | using IntervalSet = boost::icl::split_interval_map< | 96 | using IntervalSet = boost::icl::split_interval_map< |
| 96 | AddressType, s32, boost::icl::partial_enricher, std::less, boost::icl::inplace_plus, | 97 | AddressType, s32, boost::icl::partial_enricher, std::less, boost::icl::inplace_plus, |
| 97 | boost::icl::inter_section, | 98 | boost::icl::inter_section, |
| 98 | ICL_INTERVAL_INSTANCE(ICL_INTERVAL_DEFAULT, AddressType, std::less), MyAllocator>; | 99 | ICL_INTERVAL_INSTANCE(ICL_INTERVAL_DEFAULT, AddressType, std::less), RangeSetsAllocator>; |
| 99 | using IntervalType = typename IntervalSet::interval_type; | 100 | using IntervalType = typename IntervalSet::interval_type; |
| 100 | 101 | ||
| 101 | SplitRangeSetImpl() = default; | 102 | OverlapRangeSetImpl() = default; |
| 102 | ~SplitRangeSetImpl() = default; | 103 | ~OverlapRangeSetImpl() = default; |
| 103 | 104 | ||
| 104 | void Add(AddressType base_address, size_t size) { | 105 | void Add(AddressType base_address, size_t size) { |
| 105 | AddressType end_address = base_address + static_cast<AddressType>(size); | 106 | AddressType end_address = base_address + static_cast<AddressType>(size); |
| @@ -160,7 +161,7 @@ struct SplitRangeSet<AddressType>::SplitRangeSetImpl { | |||
| 160 | } | 161 | } |
| 161 | const AddressType start_address = base_address; | 162 | const AddressType start_address = base_address; |
| 162 | const AddressType end_address = start_address + size; | 163 | const AddressType end_address = start_address + size; |
| 163 | const SplitRangeSetImpl::IntervalType search_interval{start_address, end_address}; | 164 | const OverlapRangeSetImpl::IntervalType search_interval{start_address, end_address}; |
| 164 | auto it = m_split_ranges_set.lower_bound(search_interval); | 165 | auto it = m_split_ranges_set.lower_bound(search_interval); |
| 165 | if (it == m_split_ranges_set.end()) { | 166 | if (it == m_split_ranges_set.end()) { |
| 166 | return; | 167 | return; |
| @@ -230,72 +231,74 @@ void RangeSet<AddressType>::ForEach(Func&& func) const { | |||
| 230 | 231 | ||
| 231 | template <typename AddressType> | 232 | template <typename AddressType> |
| 232 | template <typename Func> | 233 | template <typename Func> |
| 233 | void RangeSet<AddressType>::ForEachInRange(AddressType base_address, size_t size, Func&& func) const { | 234 | void RangeSet<AddressType>::ForEachInRange(AddressType base_address, size_t size, |
| 235 | Func&& func) const { | ||
| 234 | m_impl->ForEachInRange(base_address, size, std::move(func)); | 236 | m_impl->ForEachInRange(base_address, size, std::move(func)); |
| 235 | } | 237 | } |
| 236 | 238 | ||
| 237 | template <typename AddressType> | 239 | template <typename AddressType> |
| 238 | SplitRangeSet<AddressType>::SplitRangeSet() { | 240 | OverlapRangeSet<AddressType>::OverlapRangeSet() { |
| 239 | m_impl = std::make_unique<SplitRangeSet<AddressType>::SplitRangeSetImpl>(); | 241 | m_impl = std::make_unique<OverlapRangeSet<AddressType>::OverlapRangeSetImpl>(); |
| 240 | } | 242 | } |
| 241 | 243 | ||
| 242 | template <typename AddressType> | 244 | template <typename AddressType> |
| 243 | SplitRangeSet<AddressType>::~SplitRangeSet() = default; | 245 | OverlapRangeSet<AddressType>::~OverlapRangeSet() = default; |
| 244 | 246 | ||
| 245 | template <typename AddressType> | 247 | template <typename AddressType> |
| 246 | SplitRangeSet<AddressType>::SplitRangeSet(SplitRangeSet&& other) { | 248 | OverlapRangeSet<AddressType>::OverlapRangeSet(OverlapRangeSet&& other) { |
| 247 | m_impl = std::make_unique<SplitRangeSet<AddressType>::SplitRangeSetImpl>(); | 249 | m_impl = std::make_unique<OverlapRangeSet<AddressType>::OverlapRangeSetImpl>(); |
| 248 | m_impl->m_split_ranges_set = std::move(other.m_impl->m_split_ranges_set); | 250 | m_impl->m_split_ranges_set = std::move(other.m_impl->m_split_ranges_set); |
| 249 | } | 251 | } |
| 250 | 252 | ||
| 251 | template <typename AddressType> | 253 | template <typename AddressType> |
| 252 | SplitRangeSet<AddressType>& SplitRangeSet<AddressType>::operator=(SplitRangeSet&& other) { | 254 | OverlapRangeSet<AddressType>& OverlapRangeSet<AddressType>::operator=(OverlapRangeSet&& other) { |
| 253 | m_impl->m_split_ranges_set = std::move(other.m_impl->m_split_ranges_set); | 255 | m_impl->m_split_ranges_set = std::move(other.m_impl->m_split_ranges_set); |
| 254 | } | 256 | } |
| 255 | 257 | ||
| 256 | template <typename AddressType> | 258 | template <typename AddressType> |
| 257 | void SplitRangeSet<AddressType>::Add(AddressType base_address, size_t size) { | 259 | void OverlapRangeSet<AddressType>::Add(AddressType base_address, size_t size) { |
| 258 | m_impl->Add(base_address, size); | 260 | m_impl->Add(base_address, size); |
| 259 | } | 261 | } |
| 260 | 262 | ||
| 261 | template <typename AddressType> | 263 | template <typename AddressType> |
| 262 | void SplitRangeSet<AddressType>::Subtract(AddressType base_address, size_t size) { | 264 | void OverlapRangeSet<AddressType>::Subtract(AddressType base_address, size_t size) { |
| 263 | m_impl->template Subtract<false>(base_address, size, 1, [](AddressType, AddressType) {}); | 265 | m_impl->template Subtract<false>(base_address, size, 1, [](AddressType, AddressType) {}); |
| 264 | } | 266 | } |
| 265 | 267 | ||
| 266 | template <typename AddressType> | 268 | template <typename AddressType> |
| 267 | template <typename Func> | 269 | template <typename Func> |
| 268 | void SplitRangeSet<AddressType>::Subtract(AddressType base_address, size_t size, Func&& on_delete) { | 270 | void OverlapRangeSet<AddressType>::Subtract(AddressType base_address, size_t size, |
| 271 | Func&& on_delete) { | ||
| 269 | m_impl->template Subtract<true, Func>(base_address, size, 1, std::move(on_delete)); | 272 | m_impl->template Subtract<true, Func>(base_address, size, 1, std::move(on_delete)); |
| 270 | } | 273 | } |
| 271 | 274 | ||
| 272 | template <typename AddressType> | 275 | template <typename AddressType> |
| 273 | void SplitRangeSet<AddressType>::DeleteAll(AddressType base_address, size_t size) { | 276 | void OverlapRangeSet<AddressType>::DeleteAll(AddressType base_address, size_t size) { |
| 274 | m_impl->template Subtract<false>(base_address, size, std::numeric_limits<s32>::max(), | 277 | m_impl->template Subtract<false>(base_address, size, std::numeric_limits<s32>::max(), |
| 275 | [](AddressType, AddressType) {}); | 278 | [](AddressType, AddressType) {}); |
| 276 | } | 279 | } |
| 277 | 280 | ||
| 278 | template <typename AddressType> | 281 | template <typename AddressType> |
| 279 | void SplitRangeSet<AddressType>::Clear() { | 282 | void OverlapRangeSet<AddressType>::Clear() { |
| 280 | m_impl->m_split_ranges_set.clear(); | 283 | m_impl->m_split_ranges_set.clear(); |
| 281 | } | 284 | } |
| 282 | 285 | ||
| 283 | template <typename AddressType> | 286 | template <typename AddressType> |
| 284 | bool SplitRangeSet<AddressType>::Empty() const { | 287 | bool OverlapRangeSet<AddressType>::Empty() const { |
| 285 | return m_impl->m_split_ranges_set.empty(); | 288 | return m_impl->m_split_ranges_set.empty(); |
| 286 | } | 289 | } |
| 287 | 290 | ||
| 288 | template <typename AddressType> | 291 | template <typename AddressType> |
| 289 | template <typename Func> | 292 | template <typename Func> |
| 290 | void SplitRangeSet<AddressType>::ForEach(Func&& func) const { | 293 | void OverlapRangeSet<AddressType>::ForEach(Func&& func) const { |
| 291 | m_impl->ForEach(func); | 294 | m_impl->ForEach(func); |
| 292 | } | 295 | } |
| 293 | 296 | ||
| 294 | template <typename AddressType> | 297 | template <typename AddressType> |
| 295 | template <typename Func> | 298 | template <typename Func> |
| 296 | void SplitRangeSet<AddressType>::ForEachInRange(AddressType base_address, size_t size, | 299 | void OverlapRangeSet<AddressType>::ForEachInRange(AddressType base_address, size_t size, |
| 297 | Func&& func) const { | 300 | Func&& func) const { |
| 298 | m_impl->ForEachInRange(base_address, size, std::move(func)); | 301 | m_impl->ForEachInRange(base_address, size, std::move(func)); |
| 299 | } | 302 | } |
| 300 | 303 | ||
| 301 | } // namespace Common \ No newline at end of file | 304 | } // namespace Common |