mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-12-03 01:09:36 +00:00
Optimize PlaceholderManager.UnreserveRange
This commit is contained in:
parent
93dd6d525a
commit
65f2a82b97
2 changed files with 13 additions and 11 deletions
|
@ -9,6 +9,8 @@ namespace Ryujinx.Memory.WindowsShared
|
||||||
/// <typeparam name="T">Type of the value stored on the node</typeparam>
|
/// <typeparam name="T">Type of the value stored on the node</typeparam>
|
||||||
class MappingTree<T> : IntrusiveRedBlackTree<RangeNode<T>>
|
class MappingTree<T> : IntrusiveRedBlackTree<RangeNode<T>>
|
||||||
{
|
{
|
||||||
|
private const int ArrayGrowthSize = 16;
|
||||||
|
|
||||||
public int GetNodes(ulong start, ulong end, ref RangeNode<T>[] overlaps, int overlapCount = 0)
|
public int GetNodes(ulong start, ulong end, ref RangeNode<T>[] overlaps, int overlapCount = 0)
|
||||||
{
|
{
|
||||||
RangeNode<T> node = GetNode(new RangeNode<T>(start, start + 1UL, default));
|
RangeNode<T> node = GetNode(new RangeNode<T>(start, start + 1UL, default));
|
||||||
|
@ -17,7 +19,7 @@ namespace Ryujinx.Memory.WindowsShared
|
||||||
{
|
{
|
||||||
if (overlaps.Length <= overlapCount)
|
if (overlaps.Length <= overlapCount)
|
||||||
{
|
{
|
||||||
Array.Resize(ref overlaps, overlapCount + 1);
|
Array.Resize(ref overlaps, overlapCount + ArrayGrowthSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
overlaps[overlapCount++] = node;
|
overlaps[overlapCount++] = node;
|
||||||
|
|
|
@ -86,26 +86,26 @@ namespace Ryujinx.Memory.WindowsShared
|
||||||
{
|
{
|
||||||
ulong endAddress = address + size;
|
ulong endAddress = address + size;
|
||||||
|
|
||||||
var overlaps = new RangeNode<ulong>[InitialOverlapsSize];
|
|
||||||
int count;
|
|
||||||
|
|
||||||
lock (_mappings)
|
lock (_mappings)
|
||||||
{
|
{
|
||||||
count = _mappings.GetNodes(address, endAddress, ref overlaps);
|
RangeNode<ulong> node = _mappings.GetNode(new RangeNode<ulong>(address, address + 1UL, default));
|
||||||
|
|
||||||
for (int index = 0; index < count; index++)
|
for (; node != null; node = node.Successor)
|
||||||
{
|
{
|
||||||
var overlap = overlaps[index];
|
if (IsMapped(node.Value))
|
||||||
|
|
||||||
if (IsMapped(overlap.Value))
|
|
||||||
{
|
{
|
||||||
if (!WindowsApi.UnmapViewOfFile2(WindowsApi.CurrentProcessHandle, (IntPtr)overlap.Start, 2))
|
if (!WindowsApi.UnmapViewOfFile2(WindowsApi.CurrentProcessHandle, (IntPtr)node.Start, 2))
|
||||||
{
|
{
|
||||||
throw new WindowsApiException("UnmapViewOfFile2");
|
throw new WindowsApiException("UnmapViewOfFile2");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_mappings.Remove(overlap);
|
_mappings.Remove(node);
|
||||||
|
|
||||||
|
if (node.End >= endAddress)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue