From 7dd69f2d0e314b2969d88089559815ed84acbac4 Mon Sep 17 00:00:00 2001 From: gdk Date: Tue, 30 Aug 2022 22:26:40 -0300 Subject: [PATCH] Allocation free tree lookup --- Ryujinx.Memory/WindowsShared/MappingTree.cs | 20 +++++++++++++++++-- .../WindowsShared/PlaceholderManager.cs | 11 +++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Ryujinx.Memory/WindowsShared/MappingTree.cs b/Ryujinx.Memory/WindowsShared/MappingTree.cs index 7a18d45704..97758c2b19 100644 --- a/Ryujinx.Memory/WindowsShared/MappingTree.cs +++ b/Ryujinx.Memory/WindowsShared/MappingTree.cs @@ -13,7 +13,7 @@ namespace Ryujinx.Memory.WindowsShared public int GetNodes(ulong start, ulong end, ref RangeNode[] overlaps, int overlapCount = 0) { - RangeNode node = GetNode(new RangeNode(start, start + 1UL, default)); + RangeNode node = this.GetNodeByKey(start); for (; node != null; node = node.Successor) { @@ -34,7 +34,7 @@ namespace Ryujinx.Memory.WindowsShared } } - class RangeNode : IntrusiveRedBlackTreeNode>, IComparable> + class RangeNode : IntrusiveRedBlackTreeNode>, IComparable>, IComparable { public ulong Start { get; } public ulong End { get; private set; } @@ -67,5 +67,21 @@ namespace Ryujinx.Memory.WindowsShared return 1; } } + + public int CompareTo(ulong address) + { + if (address < Start) + { + return 1; + } + else if (address <= End - 1UL) + { + return 0; + } + else + { + return -1; + } + } } } \ No newline at end of file diff --git a/Ryujinx.Memory/WindowsShared/PlaceholderManager.cs b/Ryujinx.Memory/WindowsShared/PlaceholderManager.cs index 8624f817a3..a17fea5e3b 100644 --- a/Ryujinx.Memory/WindowsShared/PlaceholderManager.cs +++ b/Ryujinx.Memory/WindowsShared/PlaceholderManager.cs @@ -1,3 +1,4 @@ +using Ryujinx.Common.Collections; using Ryujinx.Common.Memory.PartialUnmaps; using System; using System.Diagnostics; @@ -88,7 +89,7 @@ namespace Ryujinx.Memory.WindowsShared lock (_mappings) { - RangeNode node = _mappings.GetNode(new RangeNode(address, address + 1UL, default)); + RangeNode node = _mappings.GetNodeByKey(address); RangeNode successorNode; for (; node != null; node = successorNode) @@ -379,7 +380,7 @@ namespace Ryujinx.Memory.WindowsShared lock (_mappings) { - RangeNode node = _mappings.GetNode(new RangeNode(address, address + 1UL, default)); + RangeNode node = _mappings.GetNodeByKey(address); if (node == null) { @@ -481,7 +482,7 @@ namespace Ryujinx.Memory.WindowsShared lock (_mappings) { - RangeNode node = _mappings.GetNode(new RangeNode(reprotectAddress, reprotectAddress + 1UL, default)); + RangeNode node = _mappings.GetNodeByKey(reprotectAddress); RangeNode successorNode; for (; node != null; node = successorNode) @@ -580,7 +581,7 @@ namespace Ryujinx.Memory.WindowsShared lock (_protections) { - RangeNode node = _protections.GetNode(new RangeNode(address, address + 1UL, default)); + RangeNode node = _protections.GetNodeByKey(address); if (node != null && node.Start <= address && @@ -651,7 +652,7 @@ namespace Ryujinx.Memory.WindowsShared lock (_protections) { - RangeNode node = _protections.GetNode(new RangeNode(address, address + 1UL, default)); + RangeNode node = _protections.GetNodeByKey(address); RangeNode successorNode; for (; node != null; node = successorNode)