Skip to content

Commit

Permalink
from "params T[]" to "params ReadOnlySpan<T>"
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-carvalho authored and GreemDev committed Dec 20, 2024
1 parent 9c31cb4 commit 7fff58f
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 88 deletions.
3 changes: 2 additions & 1 deletion src/ARMeilleure/Decoders/DecoderHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ARMeilleure.Common;
using System;

namespace ARMeilleure.Decoders
{
Expand Down Expand Up @@ -149,7 +150,7 @@ public static long DecodeImmS14_2(int opCode)
return (((long)opCode << 45) >> 48) & ~3;
}

public static bool VectorArgumentsInvalid(bool q, params int[] args)
public static bool VectorArgumentsInvalid(bool q, params ReadOnlySpan<int> args)
{
if (q)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ARMeilleure/Instructions/SoftFallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public static V128 Tbx4(V128 dest, V128 vector, int bytes, V128 tb0, V128 tb1, V
return TblOrTbx(dest, vector, bytes, tb0, tb1, tb2, tb3);
}

private static V128 TblOrTbx(V128 dest, V128 vector, int bytes, params V128[] tb)
private static V128 TblOrTbx(V128 dest, V128 vector, int bytes, params ReadOnlySpan<V128> tb)
{
byte[] res = new byte[16];

Expand Down
2 changes: 1 addition & 1 deletion src/ARMeilleure/IntermediateRepresentation/Operation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public static Operation Operation(Instruction inst, Operand dest, Operand[] srcs
return result;
}

public static Operation Operation(Intrinsic intrin, Operand dest, params Operand[] srcs)
public static Operation Operation(Intrinsic intrin, Operand dest, params ReadOnlySpan<Operand> srcs)
{
Operation result = Make(Instruction.Extended, 0, srcs.Length);

Expand Down
10 changes: 5 additions & 5 deletions src/ARMeilleure/Translation/EmitterContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -559,27 +559,27 @@ private Operand Add(Instruction inst, Operand dest, Operand source0, Operand sou
return dest;
}

public Operand AddIntrinsic(Intrinsic intrin, params Operand[] args)
public Operand AddIntrinsic(Intrinsic intrin, params ReadOnlySpan<Operand> args)
{
return Add(intrin, Local(OperandType.V128), args);
}

public Operand AddIntrinsicInt(Intrinsic intrin, params Operand[] args)
public Operand AddIntrinsicInt(Intrinsic intrin, params ReadOnlySpan<Operand> args)
{
return Add(intrin, Local(OperandType.I32), args);
}

public Operand AddIntrinsicLong(Intrinsic intrin, params Operand[] args)
public Operand AddIntrinsicLong(Intrinsic intrin, params ReadOnlySpan<Operand> args)
{
return Add(intrin, Local(OperandType.I64), args);
}

public void AddIntrinsicNoRet(Intrinsic intrin, params Operand[] args)
public void AddIntrinsicNoRet(Intrinsic intrin, params ReadOnlySpan<Operand> args)
{
Add(intrin, default, args);
}

private Operand Add(Intrinsic intrin, Operand dest, params Operand[] sources)
private Operand Add(Intrinsic intrin, Operand dest, params ReadOnlySpan<Operand> sources)
{
NewNextBlockIfNeeded();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ private static void WriteCall(
bool skipContext,
int spillBaseOffset,
int? resultRegister,
params ulong[] callArgs)
params ReadOnlySpan<ulong> callArgs)
{
uint resultMask = 0u;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public unsafe static void WriteCallWithGuestAddress(
int tempRegister;
int tempGuestAddress = -1;

bool inlineLookup = guestAddress.Kind != OperandKind.Constant &&
bool inlineLookup = guestAddress.Kind != OperandKind.Constant &&
funcTable is { Sparse: true };

if (guestAddress.Kind == OperandKind.Constant)
Expand Down Expand Up @@ -417,7 +417,7 @@ private static void WriteCall(
nint funcPtr,
int spillBaseOffset,
int? resultRegister,
params ulong[] callArgs)
params ReadOnlySpan<ulong> callArgs)
{
uint resultMask = 0u;

Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Graphics.Gpu/Image/TexturePool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ private static int ClampLevels(Target target, int width, int height, int depthOr
/// <param name="format">The format of the texture</param>
/// <param name="components">The texture swizzle components</param>
/// <returns>The depth-stencil mode</returns>
private static DepthStencilMode GetDepthStencilMode(Format format, params SwizzleComponent[] components)
private static DepthStencilMode GetDepthStencilMode(Format format, params ReadOnlySpan<SwizzleComponent> components)
{
// R = Depth, G = Stencil.
// On 24-bits depth formats, this is inverted (Stencil is R etc).
Expand Down
4 changes: 2 additions & 2 deletions src/Ryujinx.Graphics.Vulkan/FormatCapabilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public FormatCapabilities(Vk api, PhysicalDevice physicalDevice)
_optimalTable = new FormatFeatureFlags[totalFormats];
}

public bool BufferFormatsSupport(FormatFeatureFlags flags, params Format[] formats)
public bool BufferFormatsSupport(FormatFeatureFlags flags, params ReadOnlySpan<Format> formats)
{
foreach (Format format in formats)
{
Expand All @@ -81,7 +81,7 @@ public bool BufferFormatsSupport(FormatFeatureFlags flags, params Format[] forma
return true;
}

public bool OptimalFormatsSupport(FormatFeatureFlags flags, params Format[] formats)
public bool OptimalFormatsSupport(FormatFeatureFlags flags, params ReadOnlySpan<Format> formats)
{
foreach (Format format in formats)
{
Expand Down
20 changes: 13 additions & 7 deletions src/Ryujinx.HLE/HOS/ModLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ private static IEnumerable<Cheat> GetCheatsInFile(FileInfo cheatFile)
}

// Assumes searchDirPaths don't overlap
private static void CollectMods(Dictionary<ulong, ModCache> modCaches, PatchCache patches, params string[] searchDirPaths)
private static void CollectMods(Dictionary<ulong, ModCache> modCaches, PatchCache patches, params ReadOnlySpan<string> searchDirPaths)
{
static bool IsPatchesDir(string name) => StrEquals(AmsNsoPatchDir, name) ||
StrEquals(AmsNroPatchDir, name) ||
Expand Down Expand Up @@ -453,7 +453,7 @@ static bool TryQuery(DirectoryInfo searchDir, PatchCache patches, Dictionary<ulo
patches.Initialized = true;
}

public void CollectMods(IEnumerable<ulong> applications, params string[] searchDirPaths)
public void CollectMods(IEnumerable<ulong> applications, params ReadOnlySpan<string> searchDirPaths)
{
Clear();

Expand Down Expand Up @@ -755,12 +755,18 @@ private static bool ApplyProgramPatches(IEnumerable<Mod<DirectoryInfo>> mods, in
patches[i] = new MemPatch();
}

var buildIds = programs.Select(p => p switch
var buildIds = new List<string>(programs.Length);

foreach (IExecutable p in programs)
{
NsoExecutable nso => Convert.ToHexString(nso.BuildId.ItemsRo.ToArray()).TrimEnd('0'),
NroExecutable nro => Convert.ToHexString(nro.Header.BuildId).TrimEnd('0'),
_ => string.Empty,
}).ToList();
var buildId = p switch
{
NsoExecutable nso => Convert.ToHexString(nso.BuildId.ItemsRo.ToArray()).TrimEnd('0'),
NroExecutable nro => Convert.ToHexString(nro.Header.BuildId).TrimEnd('0'),
_ => string.Empty,
};
buildIds.Add(buildId);
}

int GetIndex(string buildId) => buildIds.FindIndex(id => id == buildId); // O(n) but list is small

Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/NpadDevices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public bool Validate(int playerMin, int playerMax, ControllerType acceptedTypes,
return true;
}

public void Configure(params ControllerConfig[] configs)
public void Configure(params ReadOnlySpan<ControllerConfig> configs)
{
_configuredTypes = new ControllerType[MaxControllers];

Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/TouchDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class TouchDevice : BaseDevice
{
public TouchDevice(Switch device, bool active) : base(device, active) { }

public void Update(params TouchPoint[] points)
public void Update(params ReadOnlySpan<TouchPoint> points)
{
ref RingLifo<TouchScreenState> lifo = ref _device.Hid.SharedMemory.TouchScreen;

Expand Down
15 changes: 10 additions & 5 deletions src/Ryujinx.HLE/Loaders/Processes/ProcessLoaderHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,17 @@ public static ProcessResult LoadNsos(
ulong codeStart = ((meta.Flags & 1) != 0 ? 0x8000000UL : 0x200000UL) + CodeStartOffset;
uint codeSize = 0;

var buildIds = executables.Select(e => (e switch
var buildIds = new string[executables.Length];

for (int i = 0; i < executables.Length; i++)
{
NsoExecutable nso => Convert.ToHexString(nso.BuildId.ItemsRo.ToArray()),
NroExecutable nro => Convert.ToHexString(nro.Header.BuildId),
_ => string.Empty
}).ToUpper());
buildIds[i] = (executables[i] switch
{
NsoExecutable nso => Convert.ToHexString(nso.BuildId.ItemsRo.ToArray()),
NroExecutable nro => Convert.ToHexString(nro.Header.BuildId),
_ => string.Empty
}).ToUpper();
}

ulong[] nsoBase = new ulong[executables.Length];

Expand Down
Loading

0 comments on commit 7fff58f

Please sign in to comment.