From 9eef2e143475b610be48d709eb0d6e61476e1f98 Mon Sep 17 00:00:00 2001 From: nmzik Date: Tue, 27 Oct 2026 21:21:37 +0100 Subject: [PATCH] graphics: reuse range-set nodes when merging additions Co-authored-by: Majed-allababedi <60163390+Majed-allababedi@users.noreply.github.com> --- src/graphics/host_gpu/rangeSet.h | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/graphics/host_gpu/rangeSet.h b/src/graphics/host_gpu/rangeSet.h index ab475d558..b7ae1fedf 100644 --- a/src/graphics/host_gpu/rangeSet.h +++ b/src/graphics/host_gpu/rangeSet.h @@ -5,6 +5,7 @@ #include #include +#include #include 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) {