diff --git a/Ryujinx.Memory/Range/NonOverlappingRangeList.cs b/Ryujinx.Memory/Range/NonOverlappingRangeList.cs
index 9a8f84dd63..60b2b37847 100644
--- a/Ryujinx.Memory/Range/NonOverlappingRangeList.cs
+++ b/Ryujinx.Memory/Range/NonOverlappingRangeList.cs
@@ -97,10 +97,8 @@ namespace Ryujinx.Memory.Range
/// The new region (high part)
private T Split(T region, ulong splitAddress)
{
- Remove(region);
-
T newRegion = (T)region.Split(splitAddress);
- Add(region);
+ Update(region);
Add(newRegion);
return newRegion;
}
diff --git a/Ryujinx.Memory/Range/RangeList.cs b/Ryujinx.Memory/Range/RangeList.cs
index 7278e7eb44..469195973f 100644
--- a/Ryujinx.Memory/Range/RangeList.cs
+++ b/Ryujinx.Memory/Range/RangeList.cs
@@ -67,6 +67,43 @@ namespace Ryujinx.Memory.Range
Insert(index, new RangeItem(item));
}
+ ///
+ /// Updates an item's end address on the list. Address must be the same.
+ ///
+ /// The item to be updated
+ /// True if the item was located and updated, false otherwise
+ public bool Update(T item)
+ {
+ int index = BinarySearch(item.Address);
+
+ if (index >= 0)
+ {
+ while (index > 0 && _items[index - 1].Address == item.Address)
+ {
+ index--;
+ }
+
+ while (index < Count)
+ {
+ if (_items[index].Value.Equals(item))
+ {
+ _items[index] = new RangeItem(item);
+
+ return true;
+ }
+
+ if (_items[index].Address > item.Address)
+ {
+ break;
+ }
+
+ index++;
+ }
+ }
+
+ return false;
+ }
+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void Insert(int index, RangeItem item)
{