0
0
Fork 0
mirror of https://github.com/GreemDev/Ryujinx.git synced 2024-12-22 16:55:49 +00:00

Add missing "yield return" (#424)

This commit is contained in:
Marco Carvalho 2024-12-22 02:28:31 -03:00 committed by GitHub
parent 67ec10feea
commit decd37ce6d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 54 additions and 95 deletions

View file

@ -230,25 +230,20 @@ namespace Ryujinx.Cpu.AppleHv
{
if (size == 0)
{
return Enumerable.Empty<HostMemoryRange>();
yield break;
}
var guestRegions = GetPhysicalRegionsImpl(va, size);
if (guestRegions == null)
{
return null;
yield break;
}
var regions = new HostMemoryRange[guestRegions.Count];
for (int i = 0; i < regions.Length; i++)
foreach (var guestRegion in guestRegions)
{
var guestRegion = guestRegions[i];
nint pointer = _backingMemory.GetPointer(guestRegion.Address, guestRegion.Size);
regions[i] = new HostMemoryRange((nuint)(ulong)pointer, guestRegion.Size);
yield return new HostMemoryRange((nuint)(ulong)pointer, guestRegion.Size);
}
return regions;
}
/// <inheritdoc/>
@ -256,23 +251,24 @@ namespace Ryujinx.Cpu.AppleHv
{
if (size == 0)
{
return Enumerable.Empty<MemoryRange>();
yield break;
}
return GetPhysicalRegionsImpl(va, size);
foreach (var physicalRegion in GetPhysicalRegionsImpl(va, size))
{
yield return physicalRegion;
}
}
private List<MemoryRange> GetPhysicalRegionsImpl(ulong va, ulong size)
private IEnumerable<MemoryRange> GetPhysicalRegionsImpl(ulong va, ulong size)
{
if (!ValidateAddress(va) || !ValidateAddressAndSize(va, size))
{
return null;
yield break;
}
int pages = GetPagesCount(va, (uint)size, out va);
var regions = new List<MemoryRange>();
ulong regionStart = GetPhysicalAddressInternal(va);
ulong regionSize = PageSize;
@ -280,14 +276,14 @@ namespace Ryujinx.Cpu.AppleHv
{
if (!ValidateAddress(va + PageSize))
{
return null;
yield break;
}
ulong newPa = GetPhysicalAddressInternal(va + PageSize);
if (GetPhysicalAddressInternal(va) + PageSize != newPa)
{
regions.Add(new MemoryRange(regionStart, regionSize));
yield return new MemoryRange(regionStart, regionSize);
regionStart = newPa;
regionSize = 0;
}
@ -296,9 +292,7 @@ namespace Ryujinx.Cpu.AppleHv
regionSize += PageSize;
}
regions.Add(new MemoryRange(regionStart, regionSize));
return regions;
yield return new MemoryRange(regionStart, regionSize);
}
/// <remarks>

View file

@ -250,25 +250,20 @@ namespace Ryujinx.Cpu.Jit
{
if (size == 0)
{
return Enumerable.Empty<HostMemoryRange>();
yield break;
}
var guestRegions = GetPhysicalRegionsImpl(va, size);
if (guestRegions == null)
{
return null;
yield break;
}
var regions = new HostMemoryRange[guestRegions.Count];
for (int i = 0; i < regions.Length; i++)
foreach (var guestRegion in guestRegions)
{
var guestRegion = guestRegions[i];
nint pointer = _backingMemory.GetPointer(guestRegion.Address, guestRegion.Size);
regions[i] = new HostMemoryRange((nuint)(ulong)pointer, guestRegion.Size);
yield return new HostMemoryRange((nuint)(ulong)pointer, guestRegion.Size);
}
return regions;
}
/// <inheritdoc/>
@ -276,23 +271,24 @@ namespace Ryujinx.Cpu.Jit
{
if (size == 0)
{
return Enumerable.Empty<MemoryRange>();
yield break;
}
return GetPhysicalRegionsImpl(va, size);
foreach (var physicalRegion in GetPhysicalRegionsImpl(va, size))
{
yield return physicalRegion;
}
}
private List<MemoryRange> GetPhysicalRegionsImpl(ulong va, ulong size)
private IEnumerable<MemoryRange> GetPhysicalRegionsImpl(ulong va, ulong size)
{
if (!ValidateAddress(va) || !ValidateAddressAndSize(va, size))
{
return null;
yield break;
}
int pages = GetPagesCount(va, (uint)size, out va);
var regions = new List<MemoryRange>();
ulong regionStart = GetPhysicalAddressInternal(va);
ulong regionSize = PageSize;
@ -300,14 +296,14 @@ namespace Ryujinx.Cpu.Jit
{
if (!ValidateAddress(va + PageSize))
{
return null;
yield break;
}
ulong newPa = GetPhysicalAddressInternal(va + PageSize);
if (GetPhysicalAddressInternal(va) + PageSize != newPa)
{
regions.Add(new MemoryRange(regionStart, regionSize));
yield return new MemoryRange(regionStart, regionSize);
regionStart = newPa;
regionSize = 0;
}
@ -316,9 +312,7 @@ namespace Ryujinx.Cpu.Jit
regionSize += PageSize;
}
regions.Add(new MemoryRange(regionStart, regionSize));
return regions;
yield return new MemoryRange(regionStart, regionSize);
}
/// <inheritdoc/>

View file

@ -475,17 +475,15 @@ namespace Ryujinx.Cpu.Jit
return GetPhysicalRegionsImpl(va, size);
}
private List<MemoryRange> GetPhysicalRegionsImpl(ulong va, ulong size)
private IEnumerable<MemoryRange> GetPhysicalRegionsImpl(ulong va, ulong size)
{
if (!ValidateAddress(va) || !ValidateAddressAndSize(va, size))
{
return null;
yield break;
}
int pages = GetPagesCount(va, (uint)size, out va);
var regions = new List<MemoryRange>();
ulong regionStart = GetPhysicalAddressInternal(va);
ulong regionSize = PageSize;
@ -493,14 +491,14 @@ namespace Ryujinx.Cpu.Jit
{
if (!ValidateAddress(va + PageSize))
{
return null;
yield break;
}
ulong newPa = GetPhysicalAddressInternal(va + PageSize);
if (GetPhysicalAddressInternal(va) + PageSize != newPa)
{
regions.Add(new MemoryRange(regionStart, regionSize));
yield return new MemoryRange(regionStart, regionSize);
regionStart = newPa;
regionSize = 0;
}
@ -509,9 +507,7 @@ namespace Ryujinx.Cpu.Jit
regionSize += PageSize;
}
regions.Add(new MemoryRange(regionStart, regionSize));
return regions;
yield return new MemoryRange(regionStart, regionSize);
}
/// <inheritdoc/>

View file

@ -8,8 +8,6 @@ namespace Ryujinx.Cpu.LightningJit.CodeGen.Arm64
{
public IEnumerable<ulong> GetCallStack(nint framePointer, nint codeRegionStart, int codeRegionSize, nint codeRegion2Start, int codeRegion2Size)
{
List<ulong> functionPointers = new();
while (true)
{
nint functionPointer = Marshal.ReadIntPtr(framePointer, nint.Size);
@ -20,11 +18,9 @@ namespace Ryujinx.Cpu.LightningJit.CodeGen.Arm64
break;
}
functionPointers.Add((ulong)functionPointer - 4);
yield return (ulong)functionPointer - 4;
framePointer = Marshal.ReadIntPtr(framePointer);
}
return functionPointers;
}
}
}

View file

@ -168,16 +168,14 @@ namespace Ryujinx.Graphics.Vulkan
return BinarySearch(list, offset, size) >= 0;
}
public readonly List<Range> FindOverlaps(int offset, int size)
public readonly IEnumerable<Range> FindOverlaps(int offset, int size)
{
var list = _ranges;
if (list == null)
{
return null;
yield break;
}
List<Range> result = null;
int index = BinarySearch(list, offset, size);
if (index >= 0)
@ -189,12 +187,10 @@ namespace Ryujinx.Graphics.Vulkan
do
{
(result ??= new List<Range>()).Add(list[index++]);
yield return list[index++];
}
while (index < list.Count && list[index].OverlapsWith(offset, size));
}
return result;
}
private static int BinarySearch(List<Range> list, int offset, int size)

View file

@ -357,7 +357,6 @@ namespace Ryujinx.HLE.HOS
{
string cheatName = DefaultCheatName;
List<string> instructions = new();
List<Cheat> cheats = new();
using StreamReader cheatData = cheatFile.OpenText();
while (cheatData.ReadLine() is { } line)
@ -373,13 +372,13 @@ namespace Ryujinx.HLE.HOS
Logger.Warning?.Print(LogClass.ModLoader, $"Ignoring cheat '{cheatFile.FullName}' because it is malformed");
return Array.Empty<Cheat>();
yield break;
}
// Add the previous section to the list.
if (instructions.Count > 0)
{
cheats.Add(new Cheat($"<{cheatName} Cheat>", cheatFile, instructions));
yield return new Cheat($"<{cheatName} Cheat>", cheatFile, instructions);
}
// Start a new cheat section.
@ -396,10 +395,8 @@ namespace Ryujinx.HLE.HOS
// Add the last section being processed.
if (instructions.Count > 0)
{
cheats.Add(new Cheat($"<{cheatName} Cheat>", cheatFile, instructions));
yield return new Cheat($"<{cheatName} Cheat>", cheatFile, instructions);
}
return cheats;
}
// Assumes searchDirPaths don't overlap

View file

@ -106,10 +106,13 @@ namespace Ryujinx.Memory
{
if (size == 0)
{
return Enumerable.Empty<HostMemoryRange>();
yield break;
}
return GetHostRegionsImpl(va, size);
foreach (var hostRegion in GetHostRegionsImpl(va, size))
{
yield return hostRegion;
}
}
/// <inheritdoc/>
@ -117,51 +120,36 @@ namespace Ryujinx.Memory
{
if (size == 0)
{
return Enumerable.Empty<MemoryRange>();
yield break;
}
var hostRegions = GetHostRegionsImpl(va, size);
if (hostRegions == null)
{
return null;
yield break;
}
var regions = new MemoryRange[hostRegions.Count];
ulong backingStart = (ulong)_backingMemory.Pointer;
ulong backingEnd = backingStart + _backingMemory.Size;
int count = 0;
for (int i = 0; i < regions.Length; i++)
foreach (var hostRegion in hostRegions)
{
var hostRegion = hostRegions[i];
if (hostRegion.Address >= backingStart && hostRegion.Address < backingEnd)
{
regions[count++] = new MemoryRange(hostRegion.Address - backingStart, hostRegion.Size);
yield return new MemoryRange(hostRegion.Address - backingStart, hostRegion.Size);
}
}
if (count != regions.Length)
{
return new ArraySegment<MemoryRange>(regions, 0, count);
}
return regions;
}
private List<HostMemoryRange> GetHostRegionsImpl(ulong va, ulong size)
private IEnumerable<HostMemoryRange> GetHostRegionsImpl(ulong va, ulong size)
{
if (!ValidateAddress(va) || !ValidateAddressAndSize(va, size))
{
return null;
yield break;
}
int pages = GetPagesCount(va, size, out va);
var regions = new List<HostMemoryRange>();
nuint regionStart = GetHostAddress(va);
ulong regionSize = PageSize;
@ -169,14 +157,14 @@ namespace Ryujinx.Memory
{
if (!ValidateAddress(va + PageSize))
{
return null;
yield break;
}
nuint newHostAddress = GetHostAddress(va + PageSize);
if (GetHostAddress(va) + PageSize != newHostAddress)
{
regions.Add(new HostMemoryRange(regionStart, regionSize));
yield return new HostMemoryRange(regionStart, regionSize);
regionStart = newHostAddress;
regionSize = 0;
}
@ -185,9 +173,7 @@ namespace Ryujinx.Memory
regionSize += PageSize;
}
regions.Add(new HostMemoryRange(regionStart, regionSize));
return regions;
yield return new HostMemoryRange(regionStart, regionSize);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]