From 9049ef99fd3e7474fdd94e105efd2eb9fc39cbc7 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 6 Mar 2022 13:03:39 -0800 Subject: [PATCH] Minor allocation reduction --- .../EncounterStatic/EncounterStatic8N.cs | 2 +- .../EncounterStatic/EncounterStatic8b.cs | 16 +++++++++++++--- PKHeX.Core/Legality/RNG/Frame/SlotRange.cs | 2 +- PKHeX.Core/Legality/RNG/RaidRNG.cs | 6 +++--- .../Gen8/LA/Pokedex/PokedexConstants8a.cs | 2 +- .../Gen8/LA/Pokedex/PokedexSave8a.cs | 5 +++-- 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8N.cs b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8N.cs index 566b50abb..f9603daea 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8N.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8N.cs @@ -29,7 +29,7 @@ public EncounterStatic8N(byte nestID, uint minRank, uint maxRank, byte val, Game FlawlessIVCount = val; } - private static readonly int[] LevelCaps = + private static readonly byte[] LevelCaps = { 15, 20, // 0 25, 30, // 1 diff --git a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8b.cs b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8b.cs index 25dc4f031..86e94b83a 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8b.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8b.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using static PKHeX.Core.StaticCorrelation8bRequirement; namespace PKHeX.Core @@ -23,7 +22,18 @@ protected override bool IsMatchLocation(PKM pkm) { if (!Roaming) return base.IsMatchLocation(pkm); - return Roaming_MetLocation_BDSP.Contains(pkm.Met_Location); + return IsRoamingLocation(pkm); + } + + private static bool IsRoamingLocation(PKM pkm) + { + var location = pkm.Met_Location; + foreach (var value in Roaming_MetLocation_BDSP) + { + if (value == location) + return true; + } + return false; } public StaticCorrelation8bRequirement GetRequirement(PKM pk) => Roaming @@ -77,7 +87,7 @@ protected override void SetMetData(PKM pk, int level, DateTime today) } // defined by mvpoke in encounter data - private static readonly int[] Roaming_MetLocation_BDSP = + private static readonly ushort[] Roaming_MetLocation_BDSP = { 197, 201, 354, 355, 356, 357, 358, 359, 361, 362, 364, 365, 367, 373, 375, 377, 378, 379, 383, 385, 392, 394, 395, 397, 400, 403, 404, 407, diff --git a/PKHeX.Core/Legality/RNG/Frame/SlotRange.cs b/PKHeX.Core/Legality/RNG/Frame/SlotRange.cs index 11363faba..0208e2793 100644 --- a/PKHeX.Core/Legality/RNG/Frame/SlotRange.cs +++ b/PKHeX.Core/Legality/RNG/Frame/SlotRange.cs @@ -85,7 +85,7 @@ private static int JSlot(SlotType type, uint rand) private readonly record struct Range(uint Min, uint Max); - private static Range[] GetRanges(params uint[] rates) + private static Range[] GetRanges(params byte[] rates) { var len = rates.Length; var arr = new Range[len]; diff --git a/PKHeX.Core/Legality/RNG/RaidRNG.cs b/PKHeX.Core/Legality/RNG/RaidRNG.cs index 7e5325a7c..fba44e0f9 100644 --- a/PKHeX.Core/Legality/RNG/RaidRNG.cs +++ b/PKHeX.Core/Legality/RNG/RaidRNG.cs @@ -327,7 +327,7 @@ private static uint GetShinyXor(uint pid, uint oid) return (xor ^ (xor >> 16)) & 0xFFFF; } - private static readonly int[] Nature0 = {3, 4, 2, 8, 9, 19, 22, 11, 13, 14, 0, 6, 24}; - private static readonly int[] Nature1 = {1, 5, 7, 10, 12, 15, 16, 17, 18, 20, 21, 23}; + private static readonly byte[] Nature0 = {3, 4, 2, 8, 9, 19, 22, 11, 13, 14, 0, 6, 24}; + private static readonly byte[] Nature1 = {1, 5, 7, 10, 12, 15, 16, 17, 18, 20, 21, 23}; } -} \ No newline at end of file +} diff --git a/PKHeX.Core/Saves/Substructures/Gen8/LA/Pokedex/PokedexConstants8a.cs b/PKHeX.Core/Saves/Substructures/Gen8/LA/Pokedex/PokedexConstants8a.cs index c42454fd6..05449f09f 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/LA/Pokedex/PokedexConstants8a.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/LA/Pokedex/PokedexConstants8a.cs @@ -7,7 +7,7 @@ public static class PokedexConstants8a { public const int MaxPokedexResearchPoints = 60000; - public static readonly int[] ResearchPointsForRank = + public static readonly ushort[] ResearchPointsForRank = { 0, 500, 1800, 3500, 6000, 8500, 11000, 15000, 20000, 30000, 60000, }; diff --git a/PKHeX.Core/Saves/Substructures/Gen8/LA/Pokedex/PokedexSave8a.cs b/PKHeX.Core/Saves/Substructures/Gen8/LA/Pokedex/PokedexSave8a.cs index 6482c8af9..1b7eab9ea 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/LA/Pokedex/PokedexSave8a.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/LA/Pokedex/PokedexSave8a.cs @@ -601,10 +601,11 @@ private void UpdateAllCompleteFlags() public static int GetResearchPoint(int rank) { - if ((uint)rank >= PokedexConstants8a.ResearchPointsForRank.Length) + var table = PokedexConstants8a.ResearchPointsForRank; + if ((uint)rank >= table.Length) return 0; - return PokedexConstants8a.ResearchPointsForRank[rank]; + return table[rank]; } public int GetCurrentReportCounter() => SaveData.GetReportCounter();