Pass ribbon temp struct byref

Quicker than creating defensive copies for each Parse call. Do the same for IV-set passing.
Not worth for binlinker as it's never passed multiple times / deref'd often.
This commit is contained in:
Kurt 2023-12-30 11:40:10 -08:00
parent 581f0e2e1b
commit 581d5158dc
22 changed files with 33 additions and 34 deletions

View file

@ -42,7 +42,7 @@ public static class RibbonApplicator
/// <summary>
/// Parses the Entity for all ribbons, then fixes any ribbon that was invalid.
/// </summary>
public static void FixInvalidRibbons(RibbonVerifierArguments args)
public static void FixInvalidRibbons(in RibbonVerifierArguments args)
{
Span<RibbonResult> result = stackalloc RibbonResult[RibbonVerifier.MaxRibbonCount];
var count = RibbonVerifier.GetRibbonResults(args, result);
@ -50,7 +50,7 @@ public static class RibbonApplicator
ribbon.Fix(args);
}
private static void SetAllRibbonState(RibbonVerifierArguments args, bool desiredState)
private static void SetAllRibbonState(in RibbonVerifierArguments args, bool desiredState)
{
for (RibbonIndex3 r = 0; r < RibbonIndex3.MAX_COUNT; r++)
r.Fix(args, desiredState);

View file

@ -246,7 +246,7 @@ public static class Legal
/// <summary>
/// Checks if the input <see cref="pk"/> has IVs that match the template <see cref="IVs"/>.
/// </summary>
public static bool GetIsFixedIVSequenceValidSkipRand(IndividualValueSet IVs, PKM pk, int max = 31)
public static bool GetIsFixedIVSequenceValidSkipRand(in IndividualValueSet IVs, PKM pk, int max = 31)
{
// Template IVs not in the [0,max] range are random. Only check for IVs within the "specified" range.
if ((uint)IVs.HP <= max && IVs.HP != pk.IV_HP ) return false;
@ -261,7 +261,7 @@ public static class Legal
/// <summary>
/// Checks if the input <see cref="pk"/> has IVs that match the template <see cref="IVs"/>.
/// </summary>
public static bool GetIsFixedIVSequenceValidNoRand(IndividualValueSet IVs, PKM pk)
public static bool GetIsFixedIVSequenceValidNoRand(in IndividualValueSet IVs, PKM pk)
{
if (IVs.HP != pk.IV_HP ) return false;
if (IVs.ATK != pk.IV_ATK) return false;

View file

@ -275,7 +275,7 @@ public sealed record EncounterCriteria : IFixedNature, IFixedGender, IFixedAbili
/// </summary>
/// <param name="pk">Entity to mutate.</param>
/// <param name="template">Template to populate from</param>
public void SetRandomIVs(PKM pk, IndividualValueSet template)
public void SetRandomIVs(PKM pk, in IndividualValueSet template)
{
if (!template.IsSpecified)
{

View file

@ -37,7 +37,7 @@ public static class EncounterUtil1
_ => tr.Language == 1 ? "GF" : tr.OT,
};
public static ushort GetDV16(IndividualValueSet actual)
public static ushort GetDV16(in IndividualValueSet actual)
{
ushort result = 0;
result |= (ushort)(actual.SPA << 0);

View file

@ -41,7 +41,7 @@ public readonly record struct RibbonResult
/// <summary>
/// Updates the ribbon state depending on the <see cref="args"/> and <see cref="IsMissing"/> state.
/// </summary>
public void Fix(RibbonVerifierArguments args)
public void Fix(in RibbonVerifierArguments args)
{
switch (Type)
{

View file

@ -48,7 +48,7 @@ public sealed class RibbonVerifier : Verifier
/// <param name="index">Ribbon Index to check for</param>
/// <param name="args">Inputs to analyze</param>
/// <returns>True if not present in the flagged result span.</returns>
public static bool IsValidExtra(RibbonIndex index, RibbonVerifierArguments args)
public static bool IsValidExtra(RibbonIndex index, in RibbonVerifierArguments args)
{
Span<RibbonResult> result = stackalloc RibbonResult[MaxRibbonCount];
int count = GetRibbonResults(args, result);
@ -70,13 +70,13 @@ public sealed class RibbonVerifier : Verifier
/// <param name="args">Inputs to analyze</param>
/// <param name="result">Result storage</param>
/// <returns>Count of elements filled in the <see cref="result"/> span.</returns>
public static int GetRibbonResults(RibbonVerifierArguments args, Span<RibbonResult> result)
public static int GetRibbonResults(in RibbonVerifierArguments args, Span<RibbonResult> result)
{
var list = new RibbonResultList(result);
return GetRibbonResults(args, ref list);
}
private static int GetRibbonResults(RibbonVerifierArguments args, ref RibbonResultList list)
private static int GetRibbonResults(in RibbonVerifierArguments args, ref RibbonResultList list)
{
if (!args.Entity.IsEgg)
Parse(args, ref list);
@ -131,7 +131,7 @@ public sealed class RibbonVerifier : Verifier
}
}
private static void Parse(RibbonVerifierArguments args, ref RibbonResultList list)
private static void Parse(in RibbonVerifierArguments args, ref RibbonResultList list)
{
var pk = args.Entity;
if (pk is IRibbonSetOnly3 o3)
@ -160,7 +160,7 @@ public sealed class RibbonVerifier : Verifier
m9.Parse(args, ref list);
}
private static void ParseEgg(RibbonVerifierArguments args, ref RibbonResultList list)
private static void ParseEgg(in RibbonVerifierArguments args, ref RibbonResultList list)
{
var pk = args.Entity;
if (pk is IRibbonSetOnly3 o3)

View file

@ -7,10 +7,9 @@ namespace PKHeX.Core;
/// </summary>
public static class RibbonVerifierCommon3
{
public static void Parse(this IRibbonSetCommon3 r, RibbonVerifierArguments args, ref RibbonResultList list)
public static void Parse(this IRibbonSetCommon3 r, in RibbonVerifierArguments args, ref RibbonResultList list)
{
var evos = args.History;
var pk = args.Entity;
if (r.RibbonChampionG3 && !evos.HasVisitedGen3)
list.Add(ChampionG3);
if (r.RibbonArtist && !evos.HasVisitedGen3)

View file

@ -7,7 +7,7 @@ namespace PKHeX.Core;
/// </summary>
public static class RibbonVerifierCommon4
{
public static void Parse(this IRibbonSetCommon4 r, RibbonVerifierArguments args, ref RibbonResultList list)
public static void Parse(this IRibbonSetCommon4 r, in RibbonVerifierArguments args, ref RibbonResultList list)
{
var pk = args.Entity;
var evos = args.History;

View file

@ -7,7 +7,7 @@ namespace PKHeX.Core;
/// </summary>
public static class RibbonVerifierCommon6
{
public static void Parse(this IRibbonSetCommon6 r, RibbonVerifierArguments args, ref RibbonResultList list)
public static void Parse(this IRibbonSetCommon6 r, in RibbonVerifierArguments args, ref RibbonResultList list)
{
if (r is IRibbonSetMemory6 m)
GetInvalidRibbons6Memory(m, args, ref list);
@ -89,7 +89,7 @@ public static class RibbonVerifierCommon6
FlagContest(r, ref list);
}
private static void GetInvalidRibbons6Memory(IRibbonSetMemory6 r, RibbonVerifierArguments args, ref RibbonResultList list)
private static void GetInvalidRibbons6Memory(IRibbonSetMemory6 r, in RibbonVerifierArguments args, ref RibbonResultList list)
{
var format = args.Entity.Format;
(byte contest, byte battle) = RibbonRules.GetMaxMemoryCounts(args.History, args.Entity, args.Encounter);
@ -138,7 +138,7 @@ public static class RibbonVerifierCommon6
list.Add(MasterToughness);
}
private static void CheckChampionMemory(RibbonVerifierArguments args, ref RibbonResultList list)
private static void CheckChampionMemory(in RibbonVerifierArguments args, ref RibbonResultList list)
{
var pk = args.Entity;
var enc = args.Encounter;
@ -150,7 +150,7 @@ public static class RibbonVerifierCommon6
list.Add(ribbon, true);
}
private static void CheckMaisonRibbons(IRibbonSetCommon6 r, RibbonVerifierArguments args, ref RibbonResultList list)
private static void CheckMaisonRibbons(IRibbonSetCommon6 r, in RibbonVerifierArguments args, ref RibbonResultList list)
{
var pk = args.Entity;
if (!RibbonRules.IsAllowedBattleFrontier(pk.Species))

View file

@ -7,7 +7,7 @@ namespace PKHeX.Core;
/// </summary>
public static class RibbonVerifierCommon7
{
public static void Parse(this IRibbonSetCommon7 r, RibbonVerifierArguments args, ref RibbonResultList list)
public static void Parse(this IRibbonSetCommon7 r, in RibbonVerifierArguments args, ref RibbonResultList list)
{
bool inhabited7 = args.History.HasVisitedGen7;
bool alolaValid = RibbonRules.IsRibbonValidAlolaChamp(r, args.Encounter, inhabited7);

View file

@ -7,7 +7,7 @@ namespace PKHeX.Core;
/// </summary>
public static class RibbonVerifierCommon8
{
public static void Parse(this IRibbonSetCommon8 r, RibbonVerifierArguments args, ref RibbonResultList list)
public static void Parse(this IRibbonSetCommon8 r, in RibbonVerifierArguments args, ref RibbonResultList list)
{
var evos = args.History;
if (r.RibbonTowerMaster && !RibbonRules.IsRibbonValidTowerMaster(evos))

View file

@ -7,7 +7,7 @@ namespace PKHeX.Core;
/// </summary>
public static class RibbonVerifierCommon9
{
public static void Parse(this IRibbonSetCommon9 r, RibbonVerifierArguments args, ref RibbonResultList list)
public static void Parse(this IRibbonSetCommon9 r, in RibbonVerifierArguments args, ref RibbonResultList list)
{
if (r.RibbonChampionPaldea && !args.History.HasVisitedGen9)
list.Add(ChampionPaldea);

View file

@ -7,7 +7,7 @@ namespace PKHeX.Core;
/// </summary>
public static class RibbonVerifierEvent3
{
public static void Parse(this IRibbonSetEvent3 r, RibbonVerifierArguments args, ref RibbonResultList list)
public static void Parse(this IRibbonSetEvent3 r, in RibbonVerifierArguments args, ref RibbonResultList list)
{
var enc = args.Encounter;
if (enc is IRibbonSetEvent3 e)

View file

@ -7,7 +7,7 @@ namespace PKHeX.Core;
/// </summary>
public static class RibbonVerifierEvent4
{
public static void Parse(this IRibbonSetEvent4 r, RibbonVerifierArguments args, ref RibbonResultList list)
public static void Parse(this IRibbonSetEvent4 r, in RibbonVerifierArguments args, ref RibbonResultList list)
{
var enc = args.Encounter;
if (enc is IRibbonSetEvent4 e)
@ -84,7 +84,7 @@ public static class RibbonVerifierEvent4
list.Add(Souvenir);
}
public static void ParseEgg(this IRibbonSetEvent4 r, ref RibbonResultList list, RibbonVerifierArguments args)
public static void ParseEgg(this IRibbonSetEvent4 r, ref RibbonResultList list, in RibbonVerifierArguments args)
{
var enc = args.Encounter;
if (enc is IRibbonSetEvent4 e)

View file

@ -7,7 +7,7 @@ namespace PKHeX.Core;
/// </summary>
public static class RibbonVerifierMark9
{
public static void Parse(this IRibbonSetMark9 r, RibbonVerifierArguments args, ref RibbonResultList list)
public static void Parse(this IRibbonSetMark9 r, in RibbonVerifierArguments args, ref RibbonResultList list)
{
if (!MarkRules.IsMarkValidAlpha(args.Encounter, args.Entity))
list.Add(MarkAlpha, !r.RibbonMarkAlpha);

View file

@ -7,7 +7,7 @@ namespace PKHeX.Core;
/// </summary>
public static class RibbonVerifierOnly3
{
public static void Parse(this IRibbonSetOnly3 r, RibbonVerifierArguments args, ref RibbonResultList list)
public static void Parse(this IRibbonSetOnly3 r, in RibbonVerifierArguments args, ref RibbonResultList list)
{
if (r.RibbonWorld)
list.Add(RibbonIndex.World);

View file

@ -7,7 +7,7 @@ namespace PKHeX.Core;
/// </summary>
public static class RibbonVerifierUnique3
{
public static void Parse(this IRibbonSetUnique3 r, RibbonVerifierArguments args, ref RibbonResultList list)
public static void Parse(this IRibbonSetUnique3 r, in RibbonVerifierArguments args, ref RibbonResultList list)
{
var evos = args.History;
if (evos.HasVisitedGen3)

View file

@ -5,7 +5,7 @@ namespace PKHeX.Core;
/// </summary>
public static class RibbonVerifierUnique4
{
public static void Parse(this IRibbonSetUnique4 r, RibbonVerifierArguments args, ref RibbonResultList list)
public static void Parse(this IRibbonSetUnique4 r, in RibbonVerifierArguments args, ref RibbonResultList list)
{
var evos = args.History;
if (!RibbonRules.IsAllowedBattleFrontier4(evos))

View file

@ -916,10 +916,10 @@ public abstract class PKM : ISpeciesForm, ITrainerID32, IGeneration, IShiny, ILa
public void SetRandomIVs(int minFlawless = 0) => SetRandomIVs(stackalloc int[6], minFlawless);
/// <inheritdoc cref="SetRandomIVs(Span{int},int)"/>
public void SetRandomIVs(IndividualValueSet template) => SetRandomIVs(stackalloc int[6], template);
public void SetRandomIVs(in IndividualValueSet template) => SetRandomIVs(stackalloc int[6], template);
/// <inheritdoc cref="SetRandomIVs(Span{int},int)"/>
public void SetRandomIVs(Span<int> ivs, IndividualValueSet template)
public void SetRandomIVs(Span<int> ivs, in IndividualValueSet template)
{
var rnd = Util.Rand;
for (int i = 0; i < ivs.Length; i++)

View file

@ -39,7 +39,7 @@ public enum RibbonIndex3 : byte
public static class RibbonIndex3Extensions
{
public static void Fix(this RibbonIndex3 r, RibbonVerifierArguments args, bool state)
public static void Fix(this RibbonIndex3 r, in RibbonVerifierArguments args, bool state)
{
var pk = args.Entity;
if (r is Victory or Winning)

View file

@ -43,7 +43,7 @@ public enum RibbonIndex4 : byte
public static class RibbonIndex4Extensions
{
public static void Fix(this RibbonIndex4 r, RibbonVerifierArguments args, bool state)
public static void Fix(this RibbonIndex4 r, in RibbonVerifierArguments args, bool state)
{
var pk = args.Entity;
if (pk is not IRibbonSetUnique4 u4)

View file

@ -265,7 +265,7 @@ public static class RibbonIndexExtensions
};
}
public static void Fix(this RibbonIndex r, RibbonVerifierArguments args, bool state)
public static void Fix(this RibbonIndex r, in RibbonVerifierArguments args, bool state)
{
var pk = args.Entity;
var group = r.GetGroup();