graphics: reuse range-set nodes when merging additions

Co-authored-by: Majed-allababedi <60163390+Majed-allababedi@users.noreply.github.com>
This commit is contained in:
nmzikandMajed-allababedi committed 2026-10-27 21:41:30 +01:00
1 parent 39faa62ebd
commit 9eef2e1434
1 file changed
+13 -7
+13 -7
View File
@@ -5,6 +5,7 @@
#include <algorithm>
#include <cstdint>
#include <iterator>
#include <map>
namespace Libs::Graphics {
@@ -17,14 +18,19 @@ public:
if (it != m_ranges.begin() && std::prev(it)->second >= address) {
it = std::prev(it);
}
uint64_t begin = address;
uint64_t last = end;
while (it != m_ranges.end() && it->first <= last) {
begin = std::min(begin, it->first);
last = std::max(last, it->second);
it = m_ranges.erase(it);
if (it == m_ranges.end() || it->first > address) {
it = m_ranges.emplace_hint(it, address, end);
} else {
if (it->second >= end) {
return;
}
it->second = end;
}
auto next = std::next(it);
while (next != m_ranges.end() && next->first <= it->second) {
it->second = std::max(it->second, next->second);
next = m_ranges.erase(next);
}
m_ranges.emplace(begin, last);
}
void Subtract(uint64_t address, uint64_t size) {