From 373fa30535bfc8fa2d5d12fe2cee319832904bbc Mon Sep 17 00:00:00 2001 From: LotP1 <68976644+LotP1@users.noreply.github.com> Date: Wed, 4 Jun 2025 02:24:00 +0200 Subject: [PATCH] update comments and remove unused functions --- src/Ryujinx.Memory/Range/RangeList.cs | 159 +------------------------- 1 file changed, 5 insertions(+), 154 deletions(-) diff --git a/src/Ryujinx.Memory/Range/RangeList.cs b/src/Ryujinx.Memory/Range/RangeList.cs index a1df8f142..d575f4583 100644 --- a/src/Ryujinx.Memory/Range/RangeList.cs +++ b/src/Ryujinx.Memory/Range/RangeList.cs @@ -257,7 +257,7 @@ namespace Ryujinx.Memory.Range /// Start address of the range /// Size in bytes of the range /// Output array where matches will be written. It is automatically resized to fit the results - /// The number of overlapping items found + /// Range information of overlapping items found public OverlapResult FindOverlaps(ulong address, ulong size, ref RangeItem[] output) { int outputIndex = 0; @@ -323,7 +323,7 @@ namespace Ryujinx.Memory.Range /// Start address of the range /// Size in bytes of the range /// Output array where matches will be written. It is automatically resized to fit the results - /// The number of overlapping items found + /// Range information of overlapping items found [MethodImpl(MethodImplOptions.AggressiveInlining)] public OverlapResult FindOverlapsNonOverlapping(ulong address, ulong size, ref RangeItem[] output) { @@ -364,7 +364,7 @@ namespace Ryujinx.Memory.Range } /// - /// Gets range of all items on the list overlapping the specified memory range. + /// Gets the range of all items on the list overlapping the specified memory range. /// /// /// This method only returns correct results if none of the items on the list overlaps with @@ -387,26 +387,6 @@ namespace Ryujinx.Memory.Range return new OverlapResult(index, endIndex); } - /// - /// Gets all items on the list with the specified memory address. - /// - /// Address to find - /// Output array where matches will be written. It is automatically resized to fit the results - /// The number of matches found - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public OverlapResult FindOverlaps(ulong address, ref RangeItem[] output) - { - (int index, int endIndex) = BinarySearchEdges(address); - - if (index >= 0) - { - Array.Resize(ref output, endIndex - index); - Array.Copy(_items, index, output, 0, endIndex - index); - } - - return new OverlapResult(index, endIndex); - } - /// /// Performs binary search on the internal list of items. /// @@ -443,136 +423,7 @@ namespace Ryujinx.Memory.Range return ~left; } - - /// - /// Performs binary search on the internal list of items. - /// - /// Start address of the range - /// List index of the left-most item that overlaps, or complement index of nearest item with lower value on the list - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private (int, int) BinarySearchEdges(ulong address) - { - if (Count == 0) - return (~0, ~0); - - if (Count == 1) - { - ref RangeItem item = ref _items[0]; - - if (item.Address == address) - { - return (0, 1); - } - - if (address < item.Address) - { - return (~0, ~0); - } - else - { - return (~1, ~1); - } - } - - int left = 0; - int right = Count - 1; - - int leftEdge = -1; - int rightEdgeMatch = -1; - int rightEdgeNoMatch = -1; - - while (left <= right) - { - int range = right - left; - - int middle = left + (range >> 1); - - ref RangeItem item = ref _items[middle]; - - bool match = item.Address == address; - - if (range == 0) - { - if (match) - { - leftEdge = middle; - break; - } - else if (address < item.Address) - { - return (~right, ~right); - } - else - { - return (~(right + 1), ~(right + 1)); - } - } - - if (match) - { - right = middle; - if (rightEdgeMatch == -1) - rightEdgeMatch = middle; - } - else if (address < item.Address) - { - right = middle - 1; - rightEdgeNoMatch = middle; - } - else - { - left = middle + 1; - } - } - - if (left > right) - { - return (~left, ~left); - } - - if (rightEdgeMatch == -1) - { - return (leftEdge, leftEdge + 1); - } - - left = rightEdgeMatch; - right = rightEdgeNoMatch > 0 ? rightEdgeNoMatch : Count - 1; - - while (left <= right) - { - int range = right - left; - - int middle = right - (range >> 1); - - ref RangeItem item = ref _items[middle]; - - bool match = item.Address == address; - - if (range == 0) - { - if (match) - return (leftEdge, middle + 1); - else - return (leftEdge, middle); - } - - if (match) - { - left = middle; - } - else if (address < item.Address) - { - right = middle - 1; - } - else - { - left = middle + 1; - } - } - - return (leftEdge, right + 1); - } - + /// /// Performs binary search for items overlapping a given memory range. /// @@ -616,7 +467,7 @@ namespace Ryujinx.Memory.Range /// /// Start address of the range /// End address of the range - /// List index of the left-most item that overlaps, or complement index of nearest item with lower value on the list + /// Range information (inclusive, exclusive) of items that overlaps, or complement index of nearest item with lower value on the list [MethodImpl(MethodImplOptions.AggressiveInlining)] private (int, int) BinarySearchEdges(ulong address, ulong endAddress) {