From 0a75b73fa43ddadf561ddeb0f923c6f3811c025b Mon Sep 17 00:00:00 2001 From: TSRBerry <20988865+TSRBerry@users.noreply.github.com> Date: Wed, 28 Jun 2023 18:34:00 +0200 Subject: [PATCH 01/11] [Ryujinx.Memory] Address dotnet-format issues (#5386) * dotnet format style --severity info Some changes were manually reverted. * dotnet format analyzers --serverity info Some changes have been minimally adapted. * Silence dotnet format IDE0059 warnings * Address or silence dotnet format IDE1006 warnings * Address dotnet format CA1816 warnings * Address or silence dotnet format CA1069 warnings * Address remaining dotnet format analyzer warnings * Address review comments * Address most dotnet format whitespace warnings * Apply dotnet format whitespace formatting A few of them have been manually reverted and the corresponding warning was silenced * Format if-blocks correctly * Another rebase, another dotnet format run * Run dotnet format after rebase and remove unused usings - analyzers - style - whitespace * Add comments to disabled warnings * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * Address review feedback * Assign Decommit to ReplacePlaceholder * Run final dotnet format pass * Organize imports again * Add trailing commas * Add missing newline --- src/Ryujinx.Memory/AddressSpaceManager.cs | 8 ++++---- src/Ryujinx.Memory/MemoryAllocationFlags.cs | 2 +- src/Ryujinx.Memory/MemoryBlock.cs | 6 +++--- src/Ryujinx.Memory/MemoryManagement.cs | 2 +- src/Ryujinx.Memory/MemoryManagementUnix.cs | 14 +++++++------- src/Ryujinx.Memory/MemoryManagementWindows.cs | 2 +- src/Ryujinx.Memory/MemoryManagerUnixHelper.cs | 8 ++++---- src/Ryujinx.Memory/MemoryMapFlags.cs | 2 +- src/Ryujinx.Memory/MemoryNotContiguousException.cs | 2 +- src/Ryujinx.Memory/MemoryPermission.cs | 2 +- src/Ryujinx.Memory/Range/HostMemoryRange.cs | 14 ++++++++++++-- src/Ryujinx.Memory/Range/IRange.cs | 2 +- src/Ryujinx.Memory/Range/MemoryRange.cs | 2 +- src/Ryujinx.Memory/Range/MultiRange.cs | 12 +++++++++++- src/Ryujinx.Memory/Range/RangeList.cs | 8 ++++---- src/Ryujinx.Memory/Tracking/MemoryTracking.cs | 8 ++++---- src/Ryujinx.Memory/Tracking/MultiRegionHandle.cs | 11 +++++++---- src/Ryujinx.Memory/Tracking/RegionHandle.cs | 14 +++++++++----- .../Tracking/SmartMultiRegionHandle.cs | 4 +++- src/Ryujinx.Memory/Tracking/VirtualRegion.cs | 9 ++++++--- src/Ryujinx.Memory/WindowsShared/MappingTree.cs | 2 +- .../WindowsShared/PlaceholderManager.cs | 12 ++++++------ src/Ryujinx.Memory/WindowsShared/WindowsApi.cs | 8 ++++---- .../WindowsShared/WindowsApiException.cs | 2 +- src/Ryujinx.Memory/WindowsShared/WindowsFlags.cs | 8 ++++---- 25 files changed, 98 insertions(+), 66 deletions(-) diff --git a/src/Ryujinx.Memory/AddressSpaceManager.cs b/src/Ryujinx.Memory/AddressSpaceManager.cs index ac89fca6d..65b4d48f2 100644 --- a/src/Ryujinx.Memory/AddressSpaceManager.cs +++ b/src/Ryujinx.Memory/AddressSpaceManager.cs @@ -136,7 +136,7 @@ namespace Ryujinx.Memory { size = Math.Min(data.Length, PageSize - (int)(va & PageMask)); - data.Slice(0, size).CopyTo(GetHostSpanContiguous(va, size)); + data[..size].CopyTo(GetHostSpanContiguous(va, size)); offset += size; } @@ -215,7 +215,7 @@ namespace Ryujinx.Memory /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - private int GetPagesCount(ulong va, uint size, out ulong startVa) + private static int GetPagesCount(ulong va, uint size, out ulong startVa) { // WARNING: Always check if ulong does not overflow during the operations. startVa = va & ~(ulong)PageMask; @@ -224,7 +224,7 @@ namespace Ryujinx.Memory return (int)(vaSpan / PageSize); } - private void ThrowMemoryNotContiguous() => throw new MemoryNotContiguousException(); + private static void ThrowMemoryNotContiguous() => throw new MemoryNotContiguousException(); [MethodImpl(MethodImplOptions.AggressiveInlining)] private bool IsContiguousAndMapped(ulong va, int size) => IsContiguous(va, size) && IsMapped(va); @@ -361,7 +361,7 @@ namespace Ryujinx.Memory { size = Math.Min(data.Length, PageSize - (int)(va & PageMask)); - GetHostSpanContiguous(va, size).CopyTo(data.Slice(0, size)); + GetHostSpanContiguous(va, size).CopyTo(data[..size]); offset += size; } diff --git a/src/Ryujinx.Memory/MemoryAllocationFlags.cs b/src/Ryujinx.Memory/MemoryAllocationFlags.cs index 6f0ef1aa9..e5fa9360d 100644 --- a/src/Ryujinx.Memory/MemoryAllocationFlags.cs +++ b/src/Ryujinx.Memory/MemoryAllocationFlags.cs @@ -47,6 +47,6 @@ namespace Ryujinx.Memory /// Indicates that the memory will be used to store JIT generated code. /// On some platforms, this requires special flags to be passed that will allow the memory to be executable. /// - Jit = 1 << 5 + Jit = 1 << 5, } } diff --git a/src/Ryujinx.Memory/MemoryBlock.cs b/src/Ryujinx.Memory/MemoryBlock.cs index e7fc47516..7d8d7cf05 100644 --- a/src/Ryujinx.Memory/MemoryBlock.cs +++ b/src/Ryujinx.Memory/MemoryBlock.cs @@ -364,9 +364,9 @@ namespace Ryujinx.Memory /// Native pointer /// Offset to add /// Native pointer with the added offset - private IntPtr PtrAddr(IntPtr pointer, ulong offset) + private static IntPtr PtrAddr(IntPtr pointer, ulong offset) { - return (IntPtr)(pointer.ToInt64() + (long)offset); + return new IntPtr(pointer.ToInt64() + (long)offset); } /// @@ -439,4 +439,4 @@ namespace Ryujinx.Memory private static void ThrowInvalidMemoryRegionException() => throw new InvalidMemoryRegionException(); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Memory/MemoryManagement.cs b/src/Ryujinx.Memory/MemoryManagement.cs index 7acf8345f..3415ba40e 100644 --- a/src/Ryujinx.Memory/MemoryManagement.cs +++ b/src/Ryujinx.Memory/MemoryManagement.cs @@ -203,4 +203,4 @@ namespace Ryujinx.Memory } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Memory/MemoryManagementUnix.cs b/src/Ryujinx.Memory/MemoryManagementUnix.cs index 4314c3928..9827b59be 100644 --- a/src/Ryujinx.Memory/MemoryManagementUnix.cs +++ b/src/Ryujinx.Memory/MemoryManagementUnix.cs @@ -50,7 +50,7 @@ namespace Ryujinx.Memory } } - IntPtr ptr = mmap(IntPtr.Zero, size, prot, flags, -1, 0); + IntPtr ptr = Mmap(IntPtr.Zero, size, prot, flags, -1, 0); if (ptr == MAP_FAILED) { @@ -115,7 +115,7 @@ namespace Ryujinx.Memory MemoryPermission.ReadAndExecute => MmapProts.PROT_READ | MmapProts.PROT_EXEC, MemoryPermission.ReadWriteExecute => MmapProts.PROT_READ | MmapProts.PROT_WRITE | MmapProts.PROT_EXEC, MemoryPermission.Execute => MmapProts.PROT_EXEC, - _ => throw new MemoryProtectionException(permission) + _ => throw new MemoryProtectionException(permission), }; } @@ -185,12 +185,12 @@ namespace Ryujinx.Memory public static void DestroySharedMemory(IntPtr handle) { - close((int)handle); + close(handle.ToInt32()); } public static IntPtr MapSharedMemory(IntPtr handle, ulong size) { - return mmap(IntPtr.Zero, size, MmapProts.PROT_READ | MmapProts.PROT_WRITE, MmapFlags.MAP_SHARED, (int)handle, 0); + return Mmap(IntPtr.Zero, size, MmapProts.PROT_READ | MmapProts.PROT_WRITE, MmapFlags.MAP_SHARED, handle.ToInt32(), 0); } public static void UnmapSharedMemory(IntPtr address, ulong size) @@ -200,12 +200,12 @@ namespace Ryujinx.Memory public static void MapView(IntPtr sharedMemory, ulong srcOffset, IntPtr location, ulong size) { - mmap(location, size, MmapProts.PROT_READ | MmapProts.PROT_WRITE, MmapFlags.MAP_FIXED | MmapFlags.MAP_SHARED, (int)sharedMemory, (long)srcOffset); + Mmap(location, size, MmapProts.PROT_READ | MmapProts.PROT_WRITE, MmapFlags.MAP_FIXED | MmapFlags.MAP_SHARED, sharedMemory.ToInt32(), (long)srcOffset); } public static void UnmapView(IntPtr location, ulong size) { - mmap(location, size, MmapProts.PROT_NONE, MmapFlags.MAP_FIXED | MmapFlags.MAP_PRIVATE | MmapFlags.MAP_ANONYMOUS | MmapFlags.MAP_NORESERVE, -1, 0); + Mmap(location, size, MmapProts.PROT_NONE, MmapFlags.MAP_FIXED | MmapFlags.MAP_PRIVATE | MmapFlags.MAP_ANONYMOUS | MmapFlags.MAP_NORESERVE, -1, 0); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Memory/MemoryManagementWindows.cs b/src/Ryujinx.Memory/MemoryManagementWindows.cs index aaed5a637..b5be5b3cf 100644 --- a/src/Ryujinx.Memory/MemoryManagementWindows.cs +++ b/src/Ryujinx.Memory/MemoryManagementWindows.cs @@ -148,4 +148,4 @@ namespace Ryujinx.Memory } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Memory/MemoryManagerUnixHelper.cs b/src/Ryujinx.Memory/MemoryManagerUnixHelper.cs index a7b207ab0..6f36a6d56 100644 --- a/src/Ryujinx.Memory/MemoryManagerUnixHelper.cs +++ b/src/Ryujinx.Memory/MemoryManagerUnixHelper.cs @@ -14,7 +14,7 @@ namespace Ryujinx.Memory PROT_NONE = 0, PROT_READ = 1, PROT_WRITE = 2, - PROT_EXEC = 4 + PROT_EXEC = 4, } [Flags] @@ -26,7 +26,7 @@ namespace Ryujinx.Memory MAP_NORESERVE = 8, MAP_FIXED = 16, MAP_UNLOCKED = 32, - MAP_JIT_DARWIN = 0x800 + MAP_JIT_DARWIN = 0x800, } [Flags] @@ -164,9 +164,9 @@ namespace Ryujinx.Memory return result; } - public static IntPtr mmap(IntPtr address, ulong length, MmapProts prot, MmapFlags flags, int fd, long offset) + public static IntPtr Mmap(IntPtr address, ulong length, MmapProts prot, MmapFlags flags, int fd, long offset) { return Internal_mmap(address, length, prot, MmapFlagsToSystemFlags(flags), fd, offset); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Memory/MemoryMapFlags.cs b/src/Ryujinx.Memory/MemoryMapFlags.cs index b4c74c8c9..5c023cc12 100644 --- a/src/Ryujinx.Memory/MemoryMapFlags.cs +++ b/src/Ryujinx.Memory/MemoryMapFlags.cs @@ -18,6 +18,6 @@ namespace Ryujinx.Memory /// and allocate its own private storage for the mapping. /// This allows some mappings that would otherwise fail due to host platform restrictions to succeed. /// - Private = 1 << 0 + Private = 1 << 0, } } diff --git a/src/Ryujinx.Memory/MemoryNotContiguousException.cs b/src/Ryujinx.Memory/MemoryNotContiguousException.cs index 3106955b8..3468adb99 100644 --- a/src/Ryujinx.Memory/MemoryNotContiguousException.cs +++ b/src/Ryujinx.Memory/MemoryNotContiguousException.cs @@ -16,4 +16,4 @@ namespace Ryujinx.Memory { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Memory/MemoryPermission.cs b/src/Ryujinx.Memory/MemoryPermission.cs index 8c3e33cf7..6e71d7b8c 100644 --- a/src/Ryujinx.Memory/MemoryPermission.cs +++ b/src/Ryujinx.Memory/MemoryPermission.cs @@ -46,6 +46,6 @@ namespace Ryujinx.Memory /// /// Indicates an invalid protection. /// - Invalid = 255 + Invalid = 255, } } diff --git a/src/Ryujinx.Memory/Range/HostMemoryRange.cs b/src/Ryujinx.Memory/Range/HostMemoryRange.cs index 79c649d85..a4abebb54 100644 --- a/src/Ryujinx.Memory/Range/HostMemoryRange.cs +++ b/src/Ryujinx.Memory/Range/HostMemoryRange.cs @@ -5,12 +5,12 @@ namespace Ryujinx.Memory.Range /// /// Range of memory composed of an address and size. /// - public struct HostMemoryRange : IEquatable + public readonly struct HostMemoryRange : IEquatable { /// /// An empty memory range, with a null address and zero size. /// - public static HostMemoryRange Empty => new HostMemoryRange(0, 0); + public static HostMemoryRange Empty => new(0, 0); /// /// Start address of the range. @@ -67,5 +67,15 @@ namespace Ryujinx.Memory.Range { return HashCode.Combine(Address, Size); } + + public static bool operator ==(HostMemoryRange left, HostMemoryRange right) + { + return left.Equals(right); + } + + public static bool operator !=(HostMemoryRange left, HostMemoryRange right) + { + return !(left == right); + } } } diff --git a/src/Ryujinx.Memory/Range/IRange.cs b/src/Ryujinx.Memory/Range/IRange.cs index 1685396d1..c85e21d1d 100644 --- a/src/Ryujinx.Memory/Range/IRange.cs +++ b/src/Ryujinx.Memory/Range/IRange.cs @@ -28,4 +28,4 @@ namespace Ryujinx.Memory.Range /// True if overlapping, false otherwise bool OverlapsWith(ulong address, ulong size); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Memory/Range/MemoryRange.cs b/src/Ryujinx.Memory/Range/MemoryRange.cs index c7ee6db22..7e7b84b51 100644 --- a/src/Ryujinx.Memory/Range/MemoryRange.cs +++ b/src/Ryujinx.Memory/Range/MemoryRange.cs @@ -8,7 +8,7 @@ /// /// An empty memory range, with a null address and zero size. /// - public static MemoryRange Empty => new MemoryRange(0UL, 0); + public static MemoryRange Empty => new(0UL, 0); /// /// Start address of the range. diff --git a/src/Ryujinx.Memory/Range/MultiRange.cs b/src/Ryujinx.Memory/Range/MultiRange.cs index 42ef24be6..7011e528e 100644 --- a/src/Ryujinx.Memory/Range/MultiRange.cs +++ b/src/Ryujinx.Memory/Range/MultiRange.cs @@ -310,7 +310,7 @@ namespace Ryujinx.Memory.Range return _singleRange.GetHashCode(); } - HashCode hash = new HashCode(); + HashCode hash = new(); foreach (MemoryRange range in _ranges) { @@ -328,5 +328,15 @@ namespace Ryujinx.Memory.Range { return HasSingleRange ? _singleRange.ToString() : string.Join(", ", _ranges); } + + public static bool operator ==(MultiRange left, MultiRange right) + { + return left.Equals(right); + } + + public static bool operator !=(MultiRange left, MultiRange right) + { + return !(left == right); + } } } diff --git a/src/Ryujinx.Memory/Range/RangeList.cs b/src/Ryujinx.Memory/Range/RangeList.cs index 469195973..72cef1de0 100644 --- a/src/Ryujinx.Memory/Range/RangeList.cs +++ b/src/Ryujinx.Memory/Range/RangeList.cs @@ -238,7 +238,7 @@ namespace Ryujinx.Memory.Range if (index < 0) { - return default(T); + return default; } return _items[index].Value; @@ -398,7 +398,7 @@ namespace Ryujinx.Memory.Range /// List index of the item, or complement index of nearest item with lower value on the list private int BinarySearch(ulong address) { - int left = 0; + int left = 0; int right = Count - 1; while (left <= right) @@ -435,7 +435,7 @@ namespace Ryujinx.Memory.Range /// List index of the item, or complement index of nearest item with lower value on the list private int BinarySearch(ulong address, ulong endAddress) { - int left = 0; + int left = 0; int right = Count - 1; while (left <= right) @@ -480,4 +480,4 @@ namespace Ryujinx.Memory.Range } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Memory/Tracking/MemoryTracking.cs b/src/Ryujinx.Memory/Tracking/MemoryTracking.cs index bf1e0ad34..ab9d98932 100644 --- a/src/Ryujinx.Memory/Tracking/MemoryTracking.cs +++ b/src/Ryujinx.Memory/Tracking/MemoryTracking.cs @@ -21,7 +21,7 @@ namespace Ryujinx.Memory.Tracking /// This lock must be obtained when traversing or updating the region-handle hierarchy. /// It is not required when reading dirty flags. /// - internal object TrackingLock = new object(); + internal object TrackingLock = new(); /// /// Create a new tracking structure for the given "physical" memory block, @@ -114,7 +114,7 @@ namespace Ryujinx.Memory.Tracking /// A list of virtual regions within the given range internal List GetVirtualRegionsForHandle(ulong va, ulong size) { - List result = new List(); + List result = new(); _virtualRegions.GetOrAddRegions(result, va, size, (va, size) => new VirtualRegion(this, va, size)); return result; @@ -172,7 +172,7 @@ namespace Ryujinx.Memory.Tracking lock (TrackingLock) { bool mapped = _memoryManager.IsRangeMapped(address, size); - RegionHandle handle = new RegionHandle(this, paAddress, paSize, address, size, id, mapped); + RegionHandle handle = new(this, paAddress, paSize, address, size, id, mapped); return handle; } @@ -194,7 +194,7 @@ namespace Ryujinx.Memory.Tracking lock (TrackingLock) { bool mapped = _memoryManager.IsRangeMapped(address, size); - RegionHandle handle = new RegionHandle(this, paAddress, paSize, address, size, bitmap, bit, id, mapped); + RegionHandle handle = new(this, paAddress, paSize, address, size, bitmap, bit, id, mapped); return handle; } diff --git a/src/Ryujinx.Memory/Tracking/MultiRegionHandle.cs b/src/Ryujinx.Memory/Tracking/MultiRegionHandle.cs index 68fc5e759..5d3f20f4f 100644 --- a/src/Ryujinx.Memory/Tracking/MultiRegionHandle.cs +++ b/src/Ryujinx.Memory/Tracking/MultiRegionHandle.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Numerics; using System.Runtime.CompilerServices; using System.Threading; @@ -21,11 +22,11 @@ namespace Ryujinx.Memory.Tracking private readonly ulong Granularity; private readonly ulong Size; - private ConcurrentBitmap _dirtyBitmap; + private readonly ConcurrentBitmap _dirtyBitmap; private int _sequenceNumber; - private BitMap _sequenceNumberBitmap; - private BitMap _dirtyCheckedBitmap; + private readonly BitMap _sequenceNumberBitmap; + private readonly BitMap _dirtyCheckedBitmap; private int _uncheckedHandles; public bool Dirty { get; private set; } = true; @@ -54,7 +55,7 @@ namespace Ryujinx.Memory.Tracking // It is assumed that the provided handles do not overlap, in order, are on page boundaries, // and don't extend past the requested range. - foreach (RegionHandle handle in handles) + foreach (RegionHandle handle in handles.Cast()) { int startIndex = (int)((handle.RealAddress - address) / granularity); @@ -406,6 +407,8 @@ namespace Ryujinx.Memory.Tracking public void Dispose() { + GC.SuppressFinalize(this); + foreach (var handle in _handles) { handle.Dispose(); diff --git a/src/Ryujinx.Memory/Tracking/RegionHandle.cs b/src/Ryujinx.Memory/Tracking/RegionHandle.cs index 777944888..d36207cad 100644 --- a/src/Ryujinx.Memory/Tracking/RegionHandle.cs +++ b/src/Ryujinx.Memory/Tracking/RegionHandle.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Reflection.Metadata; using System.Threading; namespace Ryujinx.Memory.Tracking @@ -50,7 +49,7 @@ namespace Ryujinx.Memory.Tracking internal IMultiRegionHandle Parent { get; set; } - private event Action _onDirty; + private event Action OnDirty; private readonly object _preActionLock = new(); private RegionSignal _preAction; // Action to perform before a read or write. This will block the memory access. @@ -269,7 +268,7 @@ namespace Ryujinx.Memory.Tracking Dirty = true; if (!oldDirty) { - _onDirty?.Invoke(); + OnDirty?.Invoke(); } Parent?.SignalWrite(); } @@ -311,7 +310,10 @@ namespace Ryujinx.Memory.Tracking /// True if this reprotect is the result of consecutive dirty checks public void Reprotect(bool asDirty, bool consecutiveCheck = false) { - if (_volatile) return; + if (_volatile) + { + return; + } Dirty = asDirty; @@ -403,7 +405,7 @@ namespace Ryujinx.Memory.Tracking /// Action to call on dirty public void RegisterDirtyEvent(Action action) { - _onDirty += action; + OnDirty += action; } /// @@ -461,6 +463,8 @@ namespace Ryujinx.Memory.Tracking { ObjectDisposedException.ThrowIf(_disposed, this); + GC.SuppressFinalize(this); + _disposed = true; lock (_tracking.TrackingLock) diff --git a/src/Ryujinx.Memory/Tracking/SmartMultiRegionHandle.cs b/src/Ryujinx.Memory/Tracking/SmartMultiRegionHandle.cs index 4acddefaf..bab00377d 100644 --- a/src/Ryujinx.Memory/Tracking/SmartMultiRegionHandle.cs +++ b/src/Ryujinx.Memory/Tracking/SmartMultiRegionHandle.cs @@ -17,7 +17,7 @@ namespace Ryujinx.Memory.Tracking private readonly ulong _address; private readonly ulong _granularity; private readonly ulong _size; - private MemoryTracking _tracking; + private readonly MemoryTracking _tracking; private readonly int _id; public bool Dirty { get; private set; } = true; @@ -271,6 +271,8 @@ namespace Ryujinx.Memory.Tracking public void Dispose() { + GC.SuppressFinalize(this); + foreach (var handle in _handles) { handle?.Dispose(); diff --git a/src/Ryujinx.Memory/Tracking/VirtualRegion.cs b/src/Ryujinx.Memory/Tracking/VirtualRegion.cs index 9651426b3..e595196c7 100644 --- a/src/Ryujinx.Memory/Tracking/VirtualRegion.cs +++ b/src/Ryujinx.Memory/Tracking/VirtualRegion.cs @@ -8,7 +8,7 @@ namespace Ryujinx.Memory.Tracking /// class VirtualRegion : AbstractRegion { - public List Handles = new List(); + public List Handles = new(); private readonly MemoryTracking _tracking; private MemoryPermission _lastPermission; @@ -86,7 +86,10 @@ namespace Ryujinx.Memory.Tracking foreach (var handle in Handles) { result &= handle.RequiredPermission; - if (result == 0) return result; + if (result == 0) + { + return result; + } } return result; } @@ -128,7 +131,7 @@ namespace Ryujinx.Memory.Tracking public override INonOverlappingRange Split(ulong splitAddress) { - VirtualRegion newRegion = new VirtualRegion(_tracking, splitAddress, EndAddress - splitAddress, _lastPermission); + VirtualRegion newRegion = new(_tracking, splitAddress, EndAddress - splitAddress, _lastPermission); Size = splitAddress - Address; // The new region inherits all of our parents. diff --git a/src/Ryujinx.Memory/WindowsShared/MappingTree.cs b/src/Ryujinx.Memory/WindowsShared/MappingTree.cs index 97758c2b1..9ca84b56b 100644 --- a/src/Ryujinx.Memory/WindowsShared/MappingTree.cs +++ b/src/Ryujinx.Memory/WindowsShared/MappingTree.cs @@ -84,4 +84,4 @@ namespace Ryujinx.Memory.WindowsShared } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Memory/WindowsShared/PlaceholderManager.cs b/src/Ryujinx.Memory/WindowsShared/PlaceholderManager.cs index 3022b6616..b68a076c4 100644 --- a/src/Ryujinx.Memory/WindowsShared/PlaceholderManager.cs +++ b/src/Ryujinx.Memory/WindowsShared/PlaceholderManager.cs @@ -31,9 +31,11 @@ namespace Ryujinx.Memory.WindowsShared _partialUnmapStatePtr = PartialUnmapState.GlobalState; - _partialUnmapTrimThread = new Thread(TrimThreadLocalMapLoop); - _partialUnmapTrimThread.Name = "CPU.PartialUnmapTrimThread"; - _partialUnmapTrimThread.IsBackground = true; + _partialUnmapTrimThread = new Thread(TrimThreadLocalMapLoop) + { + Name = "CPU.PartialUnmapTrimThread", + IsBackground = true, + }; _partialUnmapTrimThread.Start(); } @@ -704,8 +706,6 @@ namespace Ryujinx.Memory.WindowsShared count = _protections.GetNodes(address, endAddress, ref overlaps); } - ulong startAddress = address; - for (int index = 0; index < count; index++) { var protection = overlaps[index]; @@ -733,4 +733,4 @@ namespace Ryujinx.Memory.WindowsShared } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Memory/WindowsShared/WindowsApi.cs b/src/Ryujinx.Memory/WindowsShared/WindowsApi.cs index c554e3205..82903c05f 100644 --- a/src/Ryujinx.Memory/WindowsShared/WindowsApi.cs +++ b/src/Ryujinx.Memory/WindowsShared/WindowsApi.cs @@ -7,8 +7,8 @@ namespace Ryujinx.Memory.WindowsShared [SupportedOSPlatform("windows")] static partial class WindowsApi { - public static readonly IntPtr InvalidHandleValue = new IntPtr(-1); - public static readonly IntPtr CurrentProcessHandle = new IntPtr(-1); + public static readonly IntPtr InvalidHandleValue = new(-1); + public static readonly IntPtr CurrentProcessHandle = new(-1); [LibraryImport("kernel32.dll", SetLastError = true)] public static partial IntPtr VirtualAlloc( @@ -96,8 +96,8 @@ namespace Ryujinx.Memory.WindowsShared MemoryPermission.ReadAndExecute => MemoryProtection.ExecuteRead, MemoryPermission.ReadWriteExecute => MemoryProtection.ExecuteReadWrite, MemoryPermission.Execute => MemoryProtection.Execute, - _ => throw new MemoryProtectionException(permission) + _ => throw new MemoryProtectionException(permission), }; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Memory/WindowsShared/WindowsApiException.cs b/src/Ryujinx.Memory/WindowsShared/WindowsApiException.cs index 330c1842a..308006aba 100644 --- a/src/Ryujinx.Memory/WindowsShared/WindowsApiException.cs +++ b/src/Ryujinx.Memory/WindowsShared/WindowsApiException.cs @@ -23,4 +23,4 @@ namespace Ryujinx.Memory.WindowsShared return $"{functionName} returned error code 0x{WindowsApi.GetLastError():X}."; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Memory/WindowsShared/WindowsFlags.cs b/src/Ryujinx.Memory/WindowsShared/WindowsFlags.cs index ca69cfe93..7dd4215ee 100644 --- a/src/Ryujinx.Memory/WindowsShared/WindowsFlags.cs +++ b/src/Ryujinx.Memory/WindowsShared/WindowsFlags.cs @@ -10,14 +10,14 @@ namespace Ryujinx.Memory.WindowsShared Commit = 0x1000, Reserve = 0x2000, Decommit = 0x4000, - ReplacePlaceholder = 0x4000, + ReplacePlaceholder = Decommit, Release = 0x8000, ReservePlaceholder = 0x40000, Reset = 0x80000, Physical = 0x400000, TopDown = 0x100000, WriteWatch = 0x200000, - LargePages = 0x20000000 + LargePages = 0x20000000, } [Flags] @@ -33,7 +33,7 @@ namespace Ryujinx.Memory.WindowsShared ExecuteWriteCopy = 0x80, GuardModifierflag = 0x100, NoCacheModifierflag = 0x200, - WriteCombineModifierflag = 0x400 + WriteCombineModifierflag = 0x400, } [Flags] @@ -47,6 +47,6 @@ namespace Ryujinx.Memory.WindowsShared SectionCommit = 0x8000000, SectionImage = 0x1000000, SectionNoCache = 0x10000000, - SectionReserve = 0x4000000 + SectionReserve = 0x4000000, } } From fc20d9b925b83532a19467293a7cdcbaa4ef3d6b Mon Sep 17 00:00:00 2001 From: TSRBerry <20988865+TSRBerry@users.noreply.github.com> Date: Wed, 28 Jun 2023 18:41:38 +0200 Subject: [PATCH 02/11] [Ryujinx.Common] Address dotnet-format issues (#5358) * dotnet format style --severity info Some changes were manually reverted. * dotnet format analyzers --serverity info Some changes have been minimally adapted. * Restore a few unused methods and variables * Silence dotnet format IDE0060 warnings * Silence dotnet format IDE0059 warnings * Address or silence dotnet format IDE1006 warnings * Address dotnet format CA1816 warnings * Address or silence dotnet format CA2211 warnings * Silence CA1806 and CA1834 issues * Fix formatting for switch expressions * Address most dotnet format whitespace warnings * Apply dotnet format whitespace formatting A few of them have been manually reverted and the corresponding warning was silenced * Revert formatting changes for while and for-loops * Format if-blocks correctly * Run dotnet format whitespace after rebase * Run dotnet format style after rebase * Run dotnet format analyzers after rebase * Run dotnet format after rebase and remove unused usings - analyzers - style - whitespace * Add comments to disabled warnings * Remove a few unused parameters * Replace MmeShadowScratch with Array256 * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Run dotnet format after rebase * Address IDE0251 warnings * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * First dotnet format pass * Second dotnet format pass * Fix build issues * Fix StructArrayHelpers.cs * Apply suggestions from code review Co-authored-by: Ac_K * Fix return statements * Fix naming rule violations * Update src/Ryujinx.Common/Utilities/StreamUtils.cs Co-authored-by: Ac_K * Add trailing commas * Address review feedback * Address review feedback * Rename remaining type parameters to TKey and TValue * Fix manual formatting for logging levels * Fix spacing before comments --------- Co-authored-by: Ac_K --- .../Collections/IntervalTree.cs | 104 ++-- .../Collections/IntrusiveRedBlackTree.cs | 13 +- .../Collections/IntrusiveRedBlackTreeImpl.cs | 2 +- .../Collections/IntrusiveRedBlackTreeNode.cs | 2 +- .../Collections/TreeDictionary.cs | 149 ++--- .../Configuration/AntiAliasing.cs | 4 +- .../Configuration/AppDataManager.cs | 8 +- .../Configuration/AspectRatioExtensions.cs | 16 +- .../DownloadableContentContainer.cs | 2 +- ...ownloadableContentJsonSerializerContext.cs | 2 +- .../Configuration/DownloadableContentNca.cs | 6 +- .../Hid/Controller/GamepadInputId.cs | 4 +- .../GenericControllerInputConfig.cs | 6 +- .../Controller/JoyconConfigControllerStick.cs | 6 +- .../JsonMotionConfigControllerConverter.cs | 10 +- .../MotionConfigJsonSerializerContext.cs | 2 +- .../Hid/Controller/StickInputId.cs | 4 +- .../Configuration/Hid/ControllerType.cs | 18 +- .../Hid/GenericInputConfigurationCommon.cs | 6 +- .../Configuration/Hid/InputConfig.cs | 4 +- .../Hid/InputConfigJsonSerializerContext.cs | 2 +- .../Hid/JsonInputConfigConverter.cs | 10 +- src/Ryujinx.Common/Configuration/Hid/Key.cs | 4 +- .../Keyboard/GenericKeyboardInputConfig.cs | 6 +- .../Hid/Keyboard/JoyconConfigKeyboardStick.cs | 12 +- .../Configuration/Hid/KeyboardHotkeys.cs | 2 +- .../Hid/LeftJoyconCommonConfig.cs | 20 +- .../Configuration/Hid/PlayerIndex.cs | 22 +- .../Hid/RightJoyconCommonConfig.cs | 22 +- .../Configuration/HideCursorMode.cs | 4 +- .../Configuration/ScalingFilter.cs | 4 +- .../Configuration/TitleUpdateMetadata.cs | 6 +- ...itleUpdateMetadataJsonSerializerContext.cs | 2 +- .../Extensions/BinaryReaderExtensions.cs | 6 +- .../Extensions/BinaryWriterExtensions.cs | 3 +- .../NVAPI/NvapiUnicodeString.cs | 4 +- .../NVAPI/NvdrsApplicationV4.cs | 2 +- .../GraphicsDriver/NVAPI/NvdrsProfile.cs | 2 +- .../GraphicsDriver/NVAPI/NvdrsSetting.cs | 2 +- .../GraphicsDriver/NVThreadedOptimization.cs | 27 +- src/Ryujinx.Common/Hash128.cs | 8 +- .../Logging/Formatters/DefaultLogFormatter.cs | 8 +- .../Formatters/DynamicObjectFormatter.cs | 10 +- .../Logging/Formatters/ILogFormatter.cs | 2 +- src/Ryujinx.Common/Logging/LogClass.cs | 4 +- src/Ryujinx.Common/Logging/LogEventArgs.cs | 12 +- .../Logging/LogEventArgsJson.cs | 12 +- .../Logging/LogEventJsonSerializerContext.cs | 2 +- src/Ryujinx.Common/Logging/Logger.cs | 102 ++-- .../Logging/Targets/AsyncLogTargetWrapper.cs | 27 +- .../Logging/Targets/ConsoleLogTarget.cs | 20 +- .../Logging/Targets/FileLogTarget.cs | 11 +- .../Logging/Targets/JsonLogTarget.cs | 12 +- src/Ryujinx.Common/Memory/ArrayPtr.cs | 16 +- .../ByteMemoryPool.ByteMemoryPoolBuffer.cs | 4 +- src/Ryujinx.Common/Memory/ByteMemoryPool.cs | 20 +- .../Memory/MemoryStreamManager.cs | 4 +- .../PartialUnmaps/NativeReaderWriterLock.cs | 19 +- .../Memory/PartialUnmaps/PartialUnmapState.cs | 8 +- .../Memory/PartialUnmaps/ThreadLocalMap.cs | 7 +- src/Ryujinx.Common/Memory/Ptr.cs | 12 +- src/Ryujinx.Common/Memory/SpanReader.cs | 20 +- src/Ryujinx.Common/Memory/SpanWriter.cs | 16 +- .../Memory/StructArrayHelpers.cs | 520 +++++++++--------- .../Memory/StructByteArrayHelpers.cs | 12 +- src/Ryujinx.Common/PerformanceCounter.cs | 14 +- src/Ryujinx.Common/Pools/ObjectPool.cs | 2 +- src/Ryujinx.Common/Pools/SharedPools.cs | 2 +- src/Ryujinx.Common/Pools/ThreadStaticArray.cs | 5 +- src/Ryujinx.Common/ReactiveObject.cs | 6 +- src/Ryujinx.Common/ReleaseInformation.cs | 18 +- .../SystemInfo/LinuxSystemInfo.cs | 31 +- .../SystemInfo/MacOSSystemInfo.cs | 18 +- src/Ryujinx.Common/SystemInfo/SystemInfo.cs | 10 +- .../SystemInfo/WindowsSystemInfo.cs | 10 +- .../SystemInterop/DisplaySleep.cs | 6 +- .../SystemInterop/ForceDpiAware.cs | 8 +- .../SystemInterop/GdiPlusHelper.cs | 4 +- .../SystemInterop/StdErrAdapter.cs | 31 +- .../WindowsMultimediaTimerResolution.cs | 4 +- src/Ryujinx.Common/Utilities/BitUtils.cs | 17 +- .../Utilities/BitfieldExtensions.cs | 2 +- src/Ryujinx.Common/Utilities/Buffers.cs | 4 +- .../Utilities/CommonJsonContext.cs | 2 +- .../Utilities/EmbeddedResources.cs | 69 +-- src/Ryujinx.Common/Utilities/HexUtils.cs | 32 +- src/Ryujinx.Common/Utilities/JsonHelper.cs | 14 +- .../Utilities/MessagePackObjectFormatter.cs | 18 +- .../Utilities/NetworkHelpers.cs | 4 +- src/Ryujinx.Common/Utilities/StreamUtils.cs | 24 +- .../Utilities/TypedStringEnumConverter.cs | 2 +- src/Ryujinx.Common/Utilities/UInt128Utils.cs | 2 +- src/Ryujinx.Common/XXHash128.cs | 143 ++--- .../AudioRenderer/AudioRendererServer.cs | 6 +- src/Ryujinx.HLE/HOS/Services/ServerBase.cs | 2 +- .../SurfaceFlinger/IHOSBinderDriver.cs | 6 +- 96 files changed, 965 insertions(+), 969 deletions(-) diff --git a/src/Ryujinx.Common/Collections/IntervalTree.cs b/src/Ryujinx.Common/Collections/IntervalTree.cs index b5188cc7e..2ea260a5f 100644 --- a/src/Ryujinx.Common/Collections/IntervalTree.cs +++ b/src/Ryujinx.Common/Collections/IntervalTree.cs @@ -7,9 +7,9 @@ namespace Ryujinx.Common.Collections /// /// An Augmented Interval Tree based off of the "TreeDictionary"'s Red-Black Tree. Allows fast overlap checking of ranges. /// - /// Key - /// Value - public class IntervalTree : IntrusiveRedBlackTreeImpl> where K : IComparable + /// Key + /// Value + public class IntervalTree : IntrusiveRedBlackTreeImpl> where TKey : IComparable { private const int ArrayGrowthSize = 32; @@ -22,11 +22,11 @@ namespace Ryujinx.Common.Collections /// Overlaps array to place results in /// Number of values found /// is null - public int Get(K key, ref V[] overlaps) + public int Get(TKey key, ref TValue[] overlaps) { ArgumentNullException.ThrowIfNull(key); - IntervalTreeNode node = GetNode(key); + IntervalTreeNode node = GetNode(key); if (node == null) { @@ -39,7 +39,7 @@ namespace Ryujinx.Common.Collections } int overlapsCount = 0; - foreach (RangeNode value in node.Values) + foreach (RangeNode value in node.Values) { overlaps[overlapsCount++] = value.Value; } @@ -56,7 +56,7 @@ namespace Ryujinx.Common.Collections /// Index to start writing results into the array. Defaults to 0 /// Number of values found /// or is null - public int Get(K start, K end, ref V[] overlaps, int overlapCount = 0) + public int Get(TKey start, TKey end, ref TValue[] overlaps, int overlapCount = 0) { ArgumentNullException.ThrowIfNull(start); ArgumentNullException.ThrowIfNull(end); @@ -73,7 +73,7 @@ namespace Ryujinx.Common.Collections /// End of the range to insert /// Value to add /// , or are null - public void Add(K start, K end, V value) + public void Add(TKey start, TKey end, TValue value) { ArgumentNullException.ThrowIfNull(start); ArgumentNullException.ThrowIfNull(end); @@ -89,7 +89,7 @@ namespace Ryujinx.Common.Collections /// Value to remove /// is null /// Number of deleted values - public int Remove(K key, V value) + public int Remove(TKey key, TValue value) { ArgumentNullException.ThrowIfNull(key); @@ -104,9 +104,9 @@ namespace Ryujinx.Common.Collections /// Adds all the nodes in the dictionary into . /// /// A list of all RangeNodes sorted by Key Order - public List> AsList() + public List> AsList() { - List> list = new List>(); + List> list = new(); AddToList(Root, list); @@ -122,7 +122,7 @@ namespace Ryujinx.Common.Collections /// /// The node to search for RangeNodes within /// The list to add RangeNodes to - private void AddToList(IntervalTreeNode node, List> list) + private void AddToList(IntervalTreeNode node, List> list) { if (node == null) { @@ -142,11 +142,11 @@ namespace Ryujinx.Common.Collections /// Key of the node to get /// Node reference in the tree /// is null - private IntervalTreeNode GetNode(K key) + private IntervalTreeNode GetNode(TKey key) { ArgumentNullException.ThrowIfNull(key); - IntervalTreeNode node = Root; + IntervalTreeNode node = Root; while (node != null) { int cmp = key.CompareTo(node.Start); @@ -173,7 +173,7 @@ namespace Ryujinx.Common.Collections /// End of the range /// Overlaps array to place results in /// Overlaps count to update - private void GetValues(IntervalTreeNode node, K start, K end, ref V[] overlaps, ref int overlapCount) + private void GetValues(IntervalTreeNode node, TKey start, TKey end, ref TValue[] overlaps, ref int overlapCount) { if (node == null || start.CompareTo(node.Max) >= 0) { @@ -188,7 +188,7 @@ namespace Ryujinx.Common.Collections if (start.CompareTo(node.End) < 0) { // Contains this node. Add overlaps to list. - foreach (RangeNode overlap in node.Values) + foreach (RangeNode overlap in node.Values) { if (start.CompareTo(overlap.End) < 0) { @@ -212,9 +212,9 @@ namespace Ryujinx.Common.Collections /// Start of the range to insert /// End of the range to insert /// Value to insert - private void Insert(K start, K end, V value) + private void Insert(TKey start, TKey end, TValue value) { - IntervalTreeNode newNode = BSTInsert(start, end, value); + IntervalTreeNode newNode = BSTInsert(start, end, value); RestoreBalanceAfterInsertion(newNode); } @@ -223,10 +223,10 @@ namespace Ryujinx.Common.Collections /// This should only be called if the max increases - not for rebalancing or removals. /// /// The node to start propagating from - private void PropagateIncrease(IntervalTreeNode node) + private static void PropagateIncrease(IntervalTreeNode node) { - K max = node.Max; - IntervalTreeNode ptr = node; + TKey max = node.Max; + IntervalTreeNode ptr = node; while ((ptr = ptr.Parent) != null) { @@ -246,13 +246,13 @@ namespace Ryujinx.Common.Collections /// This fully recalculates the max value from all children when there is potential for it to decrease. /// /// The node to start propagating from - private void PropagateFull(IntervalTreeNode node) + private static void PropagateFull(IntervalTreeNode node) { - IntervalTreeNode ptr = node; + IntervalTreeNode ptr = node; do { - K max = ptr.End; + TKey max = ptr.End; if (ptr.Left != null && ptr.Left.Max.CompareTo(max) > 0) { @@ -278,10 +278,10 @@ namespace Ryujinx.Common.Collections /// End of the range to insert /// Value to insert /// The inserted Node - private IntervalTreeNode BSTInsert(K start, K end, V value) + private IntervalTreeNode BSTInsert(TKey start, TKey end, TValue value) { - IntervalTreeNode parent = null; - IntervalTreeNode node = Root; + IntervalTreeNode parent = null; + IntervalTreeNode node = Root; while (node != null) { @@ -297,7 +297,7 @@ namespace Ryujinx.Common.Collections } else { - node.Values.Add(new RangeNode(start, end, value)); + node.Values.Add(new RangeNode(start, end, value)); if (end.CompareTo(node.End) > 0) { @@ -313,7 +313,7 @@ namespace Ryujinx.Common.Collections return node; } } - IntervalTreeNode newNode = new IntervalTreeNode(start, end, value, parent); + IntervalTreeNode newNode = new(start, end, value, parent); if (newNode.Parent == null) { Root = newNode; @@ -338,9 +338,9 @@ namespace Ryujinx.Common.Collections /// Key to search for /// Value to delete /// Number of deleted values - private int Delete(K key, V value) + private int Delete(TKey key, TValue value) { - IntervalTreeNode nodeToDelete = GetNode(key); + IntervalTreeNode nodeToDelete = GetNode(key); if (nodeToDelete == null) { @@ -362,7 +362,7 @@ namespace Ryujinx.Common.Collections return removed; } - IntervalTreeNode replacementNode; + IntervalTreeNode replacementNode; if (LeftOf(nodeToDelete) == null || RightOf(nodeToDelete) == null) { @@ -373,7 +373,7 @@ namespace Ryujinx.Common.Collections replacementNode = PredecessorOf(nodeToDelete); } - IntervalTreeNode tmp = LeftOf(replacementNode) ?? RightOf(replacementNode); + IntervalTreeNode tmp = LeftOf(replacementNode) ?? RightOf(replacementNode); if (tmp != null) { @@ -413,7 +413,7 @@ namespace Ryujinx.Common.Collections #endregion - protected override void RotateLeft(IntervalTreeNode node) + protected override void RotateLeft(IntervalTreeNode node) { if (node != null) { @@ -423,7 +423,7 @@ namespace Ryujinx.Common.Collections } } - protected override void RotateRight(IntervalTreeNode node) + protected override void RotateRight(IntervalTreeNode node) { if (node != null) { @@ -433,7 +433,7 @@ namespace Ryujinx.Common.Collections } } - public bool ContainsKey(K key) + public bool ContainsKey(TKey key) { ArgumentNullException.ThrowIfNull(key); @@ -444,15 +444,15 @@ namespace Ryujinx.Common.Collections /// /// Represents a value and its start and end keys. /// - /// - /// - public readonly struct RangeNode + /// + /// + public readonly struct RangeNode { - public readonly K Start; - public readonly K End; - public readonly V Value; + public readonly TKey Start; + public readonly TKey End; + public readonly TValue Value; - public RangeNode(K start, K end, V value) + public RangeNode(TKey start, TKey end, TValue value) { Start = start; End = end; @@ -463,36 +463,36 @@ namespace Ryujinx.Common.Collections /// /// Represents a node in the IntervalTree which contains start and end keys of type K, and a value of generic type V. /// - /// Key type of the node - /// Value type of the node - public class IntervalTreeNode : IntrusiveRedBlackTreeNode> + /// Key type of the node + /// Value type of the node + public class IntervalTreeNode : IntrusiveRedBlackTreeNode> { /// /// The start of the range. /// - internal K Start; + internal TKey Start; /// /// The end of the range - maximum of all in the Values list. /// - internal K End; + internal TKey End; /// /// The maximum end value of this node and all its children. /// - internal K Max; + internal TKey Max; /// /// Values contained on the node that shares a common Start value. /// - internal List> Values; + internal List> Values; - internal IntervalTreeNode(K start, K end, V value, IntervalTreeNode parent) + internal IntervalTreeNode(TKey start, TKey end, TValue value, IntervalTreeNode parent) { Start = start; End = end; Max = end; - Values = new List> { new RangeNode(start, end, value) }; + Values = new List> { new RangeNode(start, end, value) }; Parent = parent; } } diff --git a/src/Ryujinx.Common/Collections/IntrusiveRedBlackTree.cs b/src/Ryujinx.Common/Collections/IntrusiveRedBlackTree.cs index 0063d91e4..9e56f707b 100644 --- a/src/Ryujinx.Common/Collections/IntrusiveRedBlackTree.cs +++ b/src/Ryujinx.Common/Collections/IntrusiveRedBlackTree.cs @@ -180,11 +180,6 @@ namespace Ryujinx.Common.Collections parent.Right = child; } - if (ParentOf(element) == old) - { - parent = element; - } - element.Color = old.Color; element.Left = old.Left; element.Right = old.Right; @@ -258,11 +253,11 @@ namespace Ryujinx.Common.Collections /// Tree to search at /// Key of the node to be found /// Node that is equal to - public static N GetNodeByKey(this IntrusiveRedBlackTree tree, K key) - where N : IntrusiveRedBlackTreeNode, IComparable, IComparable - where K : struct + public static TNode GetNodeByKey(this IntrusiveRedBlackTree tree, TKey key) + where TNode : IntrusiveRedBlackTreeNode, IComparable, IComparable + where TKey : struct { - N node = tree.RootNode; + TNode node = tree.RootNode; while (node != null) { int cmp = node.CompareTo(key); diff --git a/src/Ryujinx.Common/Collections/IntrusiveRedBlackTreeImpl.cs b/src/Ryujinx.Common/Collections/IntrusiveRedBlackTreeImpl.cs index bcb2e2a23..49f97223a 100644 --- a/src/Ryujinx.Common/Collections/IntrusiveRedBlackTreeImpl.cs +++ b/src/Ryujinx.Common/Collections/IntrusiveRedBlackTreeImpl.cs @@ -10,7 +10,7 @@ namespace Ryujinx.Common.Collections { protected const bool Black = true; protected const bool Red = false; - protected T Root = null; + protected T Root; internal T RootNode => Root; diff --git a/src/Ryujinx.Common/Collections/IntrusiveRedBlackTreeNode.cs b/src/Ryujinx.Common/Collections/IntrusiveRedBlackTreeNode.cs index 7143240da..8480d51ad 100644 --- a/src/Ryujinx.Common/Collections/IntrusiveRedBlackTreeNode.cs +++ b/src/Ryujinx.Common/Collections/IntrusiveRedBlackTreeNode.cs @@ -13,4 +13,4 @@ namespace Ryujinx.Common.Collections public T Predecessor => IntrusiveRedBlackTreeImpl.PredecessorOf((T)this); public T Successor => IntrusiveRedBlackTreeImpl.SuccessorOf((T)this); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Common/Collections/TreeDictionary.cs b/src/Ryujinx.Common/Collections/TreeDictionary.cs index d118a30cc..ff1794883 100644 --- a/src/Ryujinx.Common/Collections/TreeDictionary.cs +++ b/src/Ryujinx.Common/Collections/TreeDictionary.cs @@ -8,9 +8,9 @@ namespace Ryujinx.Common.Collections /// /// Dictionary that provides the ability for O(logN) Lookups for keys that exist in the Dictionary, and O(logN) lookups for keys immediately greater than or less than a specified key. /// - /// Key - /// Value - public class TreeDictionary : IntrusiveRedBlackTreeImpl>, IDictionary where K : IComparable + /// Key + /// Value + public class TreeDictionary : IntrusiveRedBlackTreeImpl>, IDictionary where TKey : IComparable { #region Public Methods @@ -20,11 +20,11 @@ namespace Ryujinx.Common.Collections /// Key of the node value to get /// Value associated w/ /// is null - public V Get(K key) + public TValue Get(TKey key) { ArgumentNullException.ThrowIfNull(key); - Node node = GetNode(key); + Node node = GetNode(key); if (node == null) { @@ -42,7 +42,7 @@ namespace Ryujinx.Common.Collections /// Key of the node to add /// Value of the node to add /// or are null - public void Add(K key, V value) + public void Add(TKey key, TValue value) { ArgumentNullException.ThrowIfNull(key); ArgumentNullException.ThrowIfNull(value); @@ -55,7 +55,7 @@ namespace Ryujinx.Common.Collections /// /// Key of the node to remove /// is null - public void Remove(K key) + public void Remove(TKey key) { ArgumentNullException.ThrowIfNull(key); @@ -71,9 +71,9 @@ namespace Ryujinx.Common.Collections /// Key for which to find the floor value of /// Key of node immediately less than /// is null - public K Floor(K key) + public TKey Floor(TKey key) { - Node node = FloorNode(key); + Node node = FloorNode(key); if (node != null) { return node.Key; @@ -87,9 +87,9 @@ namespace Ryujinx.Common.Collections /// Key for which to find the ceiling node of /// Key of node immediately greater than /// is null - public K Ceiling(K key) + public TKey Ceiling(TKey key) { - Node node = CeilingNode(key); + Node node = CeilingNode(key); if (node != null) { return node.Key; @@ -102,12 +102,12 @@ namespace Ryujinx.Common.Collections /// /// Key to find the successor of /// Value - public K SuccessorOf(K key) + public TKey SuccessorOf(TKey key) { - Node node = GetNode(key); + Node node = GetNode(key); if (node != null) { - Node successor = SuccessorOf(node); + Node successor = SuccessorOf(node); return successor != null ? successor.Key : default; } @@ -119,12 +119,12 @@ namespace Ryujinx.Common.Collections /// /// Key to find the predecessor of /// Value - public K PredecessorOf(K key) + public TKey PredecessorOf(TKey key) { - Node node = GetNode(key); + Node node = GetNode(key); if (node != null) { - Node predecessor = PredecessorOf(node); + Node predecessor = PredecessorOf(node); return predecessor != null ? predecessor.Key : default; } @@ -137,19 +137,19 @@ namespace Ryujinx.Common.Collections /// The key/value pairs will be added in Level Order. /// /// List to add the tree pairs into - public List> AsLevelOrderList() + public List> AsLevelOrderList() { - List> list = new List>(); + List> list = new(); - Queue> nodes = new Queue>(); + Queue> nodes = new(); if (this.Root != null) { nodes.Enqueue(this.Root); } - while (nodes.TryDequeue(out Node node)) + while (nodes.TryDequeue(out Node node)) { - list.Add(new KeyValuePair(node.Key, node.Value)); + list.Add(new KeyValuePair(node.Key, node.Value)); if (node.Left != null) { nodes.Enqueue(node.Left); @@ -166,9 +166,9 @@ namespace Ryujinx.Common.Collections /// Adds all the nodes in the dictionary into . /// /// A list of all KeyValuePairs sorted by Key Order - public List> AsList() + public List> AsList() { - List> list = new List>(); + List> list = new(); AddToList(Root, list); @@ -184,7 +184,7 @@ namespace Ryujinx.Common.Collections /// /// The node to search for nodes within /// The list to add node to - private void AddToList(Node node, List> list) + private void AddToList(Node node, List> list) { if (node == null) { @@ -193,7 +193,7 @@ namespace Ryujinx.Common.Collections AddToList(node.Left, list); - list.Add(new KeyValuePair(node.Key, node.Value)); + list.Add(new KeyValuePair(node.Key, node.Value)); AddToList(node.Right, list); } @@ -204,11 +204,11 @@ namespace Ryujinx.Common.Collections /// Key of the node to get /// Node reference in the tree /// is null - private Node GetNode(K key) + private Node GetNode(TKey key) { ArgumentNullException.ThrowIfNull(key); - Node node = Root; + Node node = Root; while (node != null) { int cmp = key.CompareTo(node.Key); @@ -235,9 +235,9 @@ namespace Ryujinx.Common.Collections /// /// Key of the node to insert /// Value of the node to insert - private void Insert(K key, V value) + private void Insert(TKey key, TValue value) { - Node newNode = BSTInsert(key, value); + Node newNode = BSTInsert(key, value); RestoreBalanceAfterInsertion(newNode); } @@ -251,10 +251,10 @@ namespace Ryujinx.Common.Collections /// Key of the node to insert /// Value of the node to insert /// The inserted Node - private Node BSTInsert(K key, V value) + private Node BSTInsert(TKey key, TValue value) { - Node parent = null; - Node node = Root; + Node parent = null; + Node node = Root; while (node != null) { @@ -274,7 +274,7 @@ namespace Ryujinx.Common.Collections return node; } } - Node newNode = new Node(key, value, parent); + Node newNode = new(key, value, parent); if (newNode.Parent == null) { Root = newNode; @@ -296,14 +296,17 @@ namespace Ryujinx.Common.Collections /// /// Key of the node to delete /// The deleted Node - private Node Delete(K key) + private Node Delete(TKey key) { // O(1) Retrieval - Node nodeToDelete = GetNode(key); + Node nodeToDelete = GetNode(key); - if (nodeToDelete == null) return null; + if (nodeToDelete == null) + { + return null; + } - Node replacementNode; + Node replacementNode; if (LeftOf(nodeToDelete) == null || RightOf(nodeToDelete) == null) { @@ -314,7 +317,7 @@ namespace Ryujinx.Common.Collections replacementNode = PredecessorOf(nodeToDelete); } - Node tmp = LeftOf(replacementNode) ?? RightOf(replacementNode); + Node tmp = LeftOf(replacementNode) ?? RightOf(replacementNode); if (tmp != null) { @@ -354,11 +357,11 @@ namespace Ryujinx.Common.Collections /// Key for which to find the floor node of /// Node whose key is immediately less than or equal to , or null if no such node is found. /// is null - private Node FloorNode(K key) + private Node FloorNode(TKey key) { ArgumentNullException.ThrowIfNull(key); - Node tmp = Root; + Node tmp = Root; while (tmp != null) { @@ -382,8 +385,8 @@ namespace Ryujinx.Common.Collections } else { - Node parent = tmp.Parent; - Node ptr = tmp; + Node parent = tmp.Parent; + Node ptr = tmp; while (parent != null && ptr == parent.Left) { ptr = parent; @@ -406,11 +409,11 @@ namespace Ryujinx.Common.Collections /// Key for which to find the ceiling node of /// Node whose key is immediately greater than or equal to , or null if no such node is found. /// is null - private Node CeilingNode(K key) + private Node CeilingNode(TKey key) { ArgumentNullException.ThrowIfNull(key); - Node tmp = Root; + Node tmp = Root; while (tmp != null) { @@ -434,8 +437,8 @@ namespace Ryujinx.Common.Collections } else { - Node parent = tmp.Parent; - Node ptr = tmp; + Node parent = tmp.Parent; + Node ptr = tmp; while (parent != null && ptr == parent.Right) { ptr = parent; @@ -457,44 +460,44 @@ namespace Ryujinx.Common.Collections #region Interface Implementations // Method descriptions are not provided as they are already included as part of the interface. - public bool ContainsKey(K key) + public bool ContainsKey(TKey key) { ArgumentNullException.ThrowIfNull(key); return GetNode(key) != null; } - bool IDictionary.Remove(K key) + bool IDictionary.Remove(TKey key) { int count = Count; Remove(key); return count > Count; } - public bool TryGetValue(K key, [MaybeNullWhen(false)] out V value) + public bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value) { ArgumentNullException.ThrowIfNull(key); - Node node = GetNode(key); + Node node = GetNode(key); value = node != null ? node.Value : default; return node != null; } - public void Add(KeyValuePair item) + public void Add(KeyValuePair item) { ArgumentNullException.ThrowIfNull(item.Key); Add(item.Key, item.Value); } - public bool Contains(KeyValuePair item) + public bool Contains(KeyValuePair item) { if (item.Key == null) { return false; } - Node node = GetNode(item.Key); + Node node = GetNode(item.Key); if (node != null) { return node.Key.Equals(item.Key) && node.Value.Equals(item.Value); @@ -502,27 +505,27 @@ namespace Ryujinx.Common.Collections return false; } - public void CopyTo(KeyValuePair[] array, int arrayIndex) + public void CopyTo(KeyValuePair[] array, int arrayIndex) { if (arrayIndex < 0 || array.Length - arrayIndex < this.Count) { throw new ArgumentOutOfRangeException(nameof(arrayIndex)); } - SortedList list = GetKeyValues(); + SortedList list = GetKeyValues(); int offset = 0; for (int i = arrayIndex; i < array.Length && offset < list.Count; i++) { - array[i] = new KeyValuePair(list.Keys[i], list.Values[i]); + array[i] = new KeyValuePair(list.Keys[i], list.Values[i]); offset++; } } - public bool Remove(KeyValuePair item) + public bool Remove(KeyValuePair item) { - Node node = GetNode(item.Key); + Node node = GetNode(item.Key); if (node == null) { @@ -539,7 +542,7 @@ namespace Ryujinx.Common.Collections return false; } - public IEnumerator> GetEnumerator() + public IEnumerator> GetEnumerator() { return GetKeyValues().GetEnumerator(); } @@ -549,13 +552,13 @@ namespace Ryujinx.Common.Collections return GetKeyValues().GetEnumerator(); } - public ICollection Keys => GetKeyValues().Keys; + public ICollection Keys => GetKeyValues().Keys; - public ICollection Values => GetKeyValues().Values; + public ICollection Values => GetKeyValues().Values; public bool IsReadOnly => false; - public V this[K key] + public TValue this[TKey key] { get => Get(key); set => Add(key, value); @@ -569,16 +572,16 @@ namespace Ryujinx.Common.Collections /// Returns a sorted list of all the node keys / values in the tree. /// /// List of node keys - private SortedList GetKeyValues() + private SortedList GetKeyValues() { - SortedList set = new SortedList(); - Queue> queue = new Queue>(); + SortedList set = new(); + Queue> queue = new(); if (Root != null) { queue.Enqueue(Root); } - while (queue.TryDequeue(out Node node)) + while (queue.TryDequeue(out Node node)) { set.Add(node.Key, node.Value); if (null != node.Left) @@ -600,14 +603,14 @@ namespace Ryujinx.Common.Collections /// /// Represents a node in the TreeDictionary which contains a key and value of generic type K and V, respectively. /// - /// Key of the node - /// Value of the node - public class Node : IntrusiveRedBlackTreeNode> where K : IComparable + /// Key of the node + /// Value of the node + public class Node : IntrusiveRedBlackTreeNode> where TKey : IComparable { - internal K Key; - internal V Value; + internal TKey Key; + internal TValue Value; - internal Node(K key, V value, Node parent) + internal Node(TKey key, TValue value, Node parent) { Key = key; Value = value; diff --git a/src/Ryujinx.Common/Configuration/AntiAliasing.cs b/src/Ryujinx.Common/Configuration/AntiAliasing.cs index 159108ae4..9ab0458cd 100644 --- a/src/Ryujinx.Common/Configuration/AntiAliasing.cs +++ b/src/Ryujinx.Common/Configuration/AntiAliasing.cs @@ -11,6 +11,6 @@ namespace Ryujinx.Common.Configuration SmaaLow, SmaaMedium, SmaaHigh, - SmaaUltra + SmaaUltra, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Common/Configuration/AppDataManager.cs b/src/Ryujinx.Common/Configuration/AppDataManager.cs index b685e7064..1dbc1f0ce 100644 --- a/src/Ryujinx.Common/Configuration/AppDataManager.cs +++ b/src/Ryujinx.Common/Configuration/AppDataManager.cs @@ -18,7 +18,7 @@ namespace Ryujinx.Common.Configuration { UserProfile, Portable, - Custom + Custom, } public static LaunchMode Mode { get; private set; } @@ -34,7 +34,7 @@ namespace Ryujinx.Common.Configuration private const string DefaultModsDir = "mods"; public static string CustomModsPath { get; set; } - public static string CustomSdModsPath {get; set; } + public static string CustomSdModsPath { get; set; } public static string CustomNandPath { get; set; } // TODO: Actually implement this into VFS public static string CustomSdCardPath { get; set; } // TODO: Actually implement this into VFS @@ -151,7 +151,7 @@ namespace Ryujinx.Common.Configuration } } - public static string GetModsPath() => CustomModsPath ?? Directory.CreateDirectory(Path.Combine(BaseDirPath, DefaultModsDir)).FullName; + public static string GetModsPath() => CustomModsPath ?? Directory.CreateDirectory(Path.Combine(BaseDirPath, DefaultModsDir)).FullName; public static string GetSdModsPath() => CustomSdModsPath ?? Directory.CreateDirectory(Path.Combine(BaseDirPath, DefaultSdcardDir, "atmosphere")).FullName; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Common/Configuration/AspectRatioExtensions.cs b/src/Ryujinx.Common/Configuration/AspectRatioExtensions.cs index 5e97ed19c..c9bf24650 100644 --- a/src/Ryujinx.Common/Configuration/AspectRatioExtensions.cs +++ b/src/Ryujinx.Common/Configuration/AspectRatioExtensions.cs @@ -11,7 +11,7 @@ namespace Ryujinx.Common.Configuration Fixed16x10, Fixed21x9, Fixed32x9, - Stretched + Stretched, } public static class AspectRatioExtensions @@ -25,12 +25,14 @@ namespace Ryujinx.Common.Configuration { return aspectRatio switch { +#pragma warning disable IDE0055 // Disable formatting AspectRatio.Fixed4x3 => 4.0f, AspectRatio.Fixed16x9 => 16.0f, AspectRatio.Fixed16x10 => 16.0f, AspectRatio.Fixed21x9 => 21.0f, AspectRatio.Fixed32x9 => 32.0f, - _ => 16.0f + _ => 16.0f, +#pragma warning restore IDE0055 }; } @@ -38,12 +40,14 @@ namespace Ryujinx.Common.Configuration { return aspectRatio switch { +#pragma warning disable IDE0055 // Disable formatting AspectRatio.Fixed4x3 => 3.0f, AspectRatio.Fixed16x9 => 9.0f, AspectRatio.Fixed16x10 => 10.0f, AspectRatio.Fixed21x9 => 9.0f, AspectRatio.Fixed32x9 => 9.0f, - _ => 9.0f + _ => 9.0f, +#pragma warning restore IDE0055 }; } @@ -51,13 +55,15 @@ namespace Ryujinx.Common.Configuration { return aspectRatio switch { +#pragma warning disable IDE0055 // Disable formatting AspectRatio.Fixed4x3 => "4:3", AspectRatio.Fixed16x9 => "16:9", AspectRatio.Fixed16x10 => "16:10", AspectRatio.Fixed21x9 => "21:9", AspectRatio.Fixed32x9 => "32:9", - _ => "Stretched" + _ => "Stretched", +#pragma warning restore IDE0055 }; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Common/Configuration/DownloadableContentContainer.cs b/src/Ryujinx.Common/Configuration/DownloadableContentContainer.cs index b6ae2f3fb..f9e68a3c2 100644 --- a/src/Ryujinx.Common/Configuration/DownloadableContentContainer.cs +++ b/src/Ryujinx.Common/Configuration/DownloadableContentContainer.cs @@ -10,4 +10,4 @@ namespace Ryujinx.Common.Configuration [JsonPropertyName("dlc_nca_list")] public List DownloadableContentNcaList { get; set; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Common/Configuration/DownloadableContentJsonSerializerContext.cs b/src/Ryujinx.Common/Configuration/DownloadableContentJsonSerializerContext.cs index 132c45a44..0dbc0a301 100644 --- a/src/Ryujinx.Common/Configuration/DownloadableContentJsonSerializerContext.cs +++ b/src/Ryujinx.Common/Configuration/DownloadableContentJsonSerializerContext.cs @@ -8,4 +8,4 @@ namespace Ryujinx.Common.Configuration public partial class DownloadableContentJsonSerializerContext : JsonSerializerContext { } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Common/Configuration/DownloadableContentNca.cs b/src/Ryujinx.Common/Configuration/DownloadableContentNca.cs index 80b67300e..dded719cf 100644 --- a/src/Ryujinx.Common/Configuration/DownloadableContentNca.cs +++ b/src/Ryujinx.Common/Configuration/DownloadableContentNca.cs @@ -7,8 +7,8 @@ namespace Ryujinx.Common.Configuration [JsonPropertyName("path")] public string FullPath { get; set; } [JsonPropertyName("title_id")] - public ulong TitleId { get; set; } + public ulong TitleId { get; set; } [JsonPropertyName("is_enabled")] - public bool Enabled { get; set; } + public bool Enabled { get; set; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Common/Configuration/Hid/Controller/GamepadInputId.cs b/src/Ryujinx.Common/Configuration/Hid/Controller/GamepadInputId.cs index ad1fa6673..78bc46f21 100644 --- a/src/Ryujinx.Common/Configuration/Hid/Controller/GamepadInputId.cs +++ b/src/Ryujinx.Common/Configuration/Hid/Controller/GamepadInputId.cs @@ -53,6 +53,6 @@ namespace Ryujinx.Common.Configuration.Hid.Controller SingleLeftTrigger1, SingleRightTrigger1, - Count + Count, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Common/Configuration/Hid/Controller/GenericControllerInputConfig.cs b/src/Ryujinx.Common/Configuration/Hid/Controller/GenericControllerInputConfig.cs index d7f0e7881..abc245bc4 100644 --- a/src/Ryujinx.Common/Configuration/Hid/Controller/GenericControllerInputConfig.cs +++ b/src/Ryujinx.Common/Configuration/Hid/Controller/GenericControllerInputConfig.cs @@ -4,7 +4,7 @@ using System.Text.Json.Serialization; namespace Ryujinx.Common.Configuration.Hid.Controller { - public class GenericControllerInputConfig : GenericInputConfigurationCommon