remove duplicate function

BinarySearchLeftEdge(ulong address) matches BinarySearch(ulong address), so the former is not needed
This commit is contained in:
LotP1 2025-06-04 02:13:31 +02:00
parent 14a542ec5f
commit bc37866ac9

View file

@ -93,7 +93,7 @@ namespace Ryujinx.Memory.Range
/// <returns>True if the item was located and updated, false otherwise</returns>
protected bool Update(T item)
{
int index = BinarySearchLeftEdge(item.Address);
int index = BinarySearch(item.Address);
if (index >= 0)
{
@ -184,7 +184,7 @@ namespace Ryujinx.Memory.Range
/// <returns>True if the item was removed, or false if it was not found</returns>
public bool Remove(T item)
{
int index = BinarySearchLeftEdge(item.Address);
int index = BinarySearch(item.Address);
if (index >= 0)
{
@ -264,7 +264,7 @@ namespace Ryujinx.Memory.Range
ulong endAddress = address + size;
int startIndex = BinarySearchLeftEdge(address);
int startIndex = BinarySearch(address);
if (startIndex < 0)
startIndex = ~startIndex;
int endIndex = -1;
@ -444,75 +444,6 @@ namespace Ryujinx.Memory.Range
return ~left;
}
/// <summary>
/// Performs binary search on the internal list of items.
/// </summary>
/// <param name="address">Address to find</param>
/// <returns>List index of the left-most item that overlaps, or complement index of nearest item with lower value on the list</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private int BinarySearchLeftEdge(ulong address)
{
if (Count == 0)
return ~0;
if (Count == 1)
{
ref RangeItem<T> item = ref _items[0];
if (address == item.Address)
{
return 0;
}
if (address < item.Address)
{
return ~0;
}
else
{
return ~1;
}
}
int left = 0;
int right = Count - 1;
while (left <= right)
{
int range = right - left;
int middle = left + (range >> 1);
ref RangeItem<T> item = ref _items[middle];
bool match = item.Address == address;
if (range == 0)
{
if (match)
return middle;
else if (address < item.Address)
return ~(right);
else
return ~(right + 1);
}
if (match)
{
right = middle;
}
else if (address < item.Address)
{
right = middle - 1;
}
else
{
left = middle + 1;
}
}
return ~left;
}
/// <summary>
/// Performs binary search on the internal list of items.
/// </summary>