From 47643f49b646e5f233df8aa975087095ad9ae91c Mon Sep 17 00:00:00 2001 From: Kurt Date: Fri, 16 Feb 2018 19:34:42 -0800 Subject: [PATCH] remove linq personalinfo bit fetch reads the bits out of the original array (saves a few ms by not allocating/gc) --- PKHeX.Core/PersonalInfo/PersonalInfo.cs | 13 +++++++------ PKHeX.Core/PersonalInfo/PersonalInfoB2W2.cs | 16 +++++++--------- PKHeX.Core/PersonalInfo/PersonalInfoBW.cs | 5 ++--- PKHeX.Core/PersonalInfo/PersonalInfoG1.cs | 6 ++---- PKHeX.Core/PersonalInfo/PersonalInfoG2.cs | 6 ++---- PKHeX.Core/PersonalInfo/PersonalInfoG4.cs | 3 +-- PKHeX.Core/PersonalInfo/PersonalInfoORAS.cs | 16 +++++++--------- PKHeX.Core/PersonalInfo/PersonalInfoSM.cs | 7 +++---- PKHeX.Core/PersonalInfo/PersonalInfoXY.cs | 8 +++----- 9 files changed, 34 insertions(+), 46 deletions(-) diff --git a/PKHeX.Core/PersonalInfo/PersonalInfo.cs b/PKHeX.Core/PersonalInfo/PersonalInfo.cs index 6350cb529..e1043fca5 100644 --- a/PKHeX.Core/PersonalInfo/PersonalInfo.cs +++ b/PKHeX.Core/PersonalInfo/PersonalInfo.cs @@ -78,11 +78,13 @@ /// public bool[][] SpecialTutors { get; protected set; } = new bool[0][]; - protected static bool[] GetBits(byte[] data) + protected static bool[] GetBits(byte[] data, int start = 0, int length = -1) { - bool[] r = new bool[data.Length<<3]; + if (length < 0) + length = data.Length; + bool[] r = new bool[length << 3]; for (int i = 0; i < r.Length; i++) - r[i] = (data[i>>3] >> (i&7) & 0x1) == 1; + r[i] = (data[start + (i >> 3)] >> (i & 7) & 0x1) == 1; return r; } protected static byte[] SetBits(bool[] bits) @@ -96,12 +98,11 @@ /// /// Injects supplementary TM/HM compatibility which is not present in the generation specific format. /// - /// - internal void AddTMHM(byte[] data) => TMHM = GetBits(data); + internal void AddTMHM(byte[] data, int start = 0, int length = -1) => TMHM = GetBits(data, start, length); /// /// Injects supplementary Type Tutor compatibility which is not present in the generation specific format. /// - internal void AddTypeTutors(byte[] data) => TypeTutors = GetBits(data); + internal void AddTypeTutors(byte[] data, int start = 0, int length = -1) => TypeTutors = GetBits(data, start, length); /// /// Gets the entry index for the input criteria, with fallback for the original species entry. diff --git a/PKHeX.Core/PersonalInfo/PersonalInfoB2W2.cs b/PKHeX.Core/PersonalInfo/PersonalInfoB2W2.cs index 804c988d6..26ec460f2 100644 --- a/PKHeX.Core/PersonalInfo/PersonalInfoB2W2.cs +++ b/PKHeX.Core/PersonalInfo/PersonalInfoB2W2.cs @@ -1,6 +1,4 @@ -using System.Linq; - -namespace PKHeX.Core +namespace PKHeX.Core { /// /// class with values from the Black 2 & White 2 games. @@ -15,14 +13,14 @@ namespace PKHeX.Core Data = data; // Unpack TMHM & Tutors - TMHM = GetBits(Data.Skip(0x28).Take(0x10).ToArray()); - TypeTutors = GetBits(Data.Skip(0x38).Take(0x4).ToArray()); + TMHM = GetBits(Data, 0x28, 0x10); + TypeTutors = GetBits(Data, 0x3, 0x4); SpecialTutors = new[] { - GetBits(Data.Skip(0x3C).Take(0x04).ToArray()), - GetBits(Data.Skip(0x40).Take(0x04).ToArray()), - GetBits(Data.Skip(0x44).Take(0x04).ToArray()), - GetBits(Data.Skip(0x48).Take(0x04).ToArray()), + GetBits(Data, 0x3C, 0x04), + GetBits(Data, 0x40, 0x04), + GetBits(Data, 0x44, 0x04), + GetBits(Data, 0x48, 0x04), }; } diff --git a/PKHeX.Core/PersonalInfo/PersonalInfoBW.cs b/PKHeX.Core/PersonalInfo/PersonalInfoBW.cs index d72bf8992..8ff40d1c9 100644 --- a/PKHeX.Core/PersonalInfo/PersonalInfoBW.cs +++ b/PKHeX.Core/PersonalInfo/PersonalInfoBW.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; namespace PKHeX.Core { @@ -17,8 +16,8 @@ namespace PKHeX.Core Data = data; // Unpack TMHM & Tutors - TMHM = GetBits(Data.Skip(0x28).Take(0x10).ToArray()); - TypeTutors = GetBits(Data.Skip(0x38).Take(0x4).ToArray()); + TMHM = GetBits(Data, 0x28, 0x10); + TypeTutors = GetBits(Data, 0x38, 0x4); } public override byte[] Write() { diff --git a/PKHeX.Core/PersonalInfo/PersonalInfoG1.cs b/PKHeX.Core/PersonalInfo/PersonalInfoG1.cs index 388fc4432..29fed794b 100644 --- a/PKHeX.Core/PersonalInfo/PersonalInfoG1.cs +++ b/PKHeX.Core/PersonalInfo/PersonalInfoG1.cs @@ -1,6 +1,4 @@ -using System.Linq; - -namespace PKHeX.Core +namespace PKHeX.Core { /// /// class with values from Generation 1 games. @@ -15,7 +13,7 @@ namespace PKHeX.Core return; Data = data; - TMHM = GetBits(Data.Skip(0x14).Take(0x8).ToArray()); + TMHM = GetBits(Data, 0x14, 0x8); } public override byte[] Write() { diff --git a/PKHeX.Core/PersonalInfo/PersonalInfoG2.cs b/PKHeX.Core/PersonalInfo/PersonalInfoG2.cs index 5ec04af87..60ce44ee2 100644 --- a/PKHeX.Core/PersonalInfo/PersonalInfoG2.cs +++ b/PKHeX.Core/PersonalInfo/PersonalInfoG2.cs @@ -1,6 +1,4 @@ -using System.Linq; - -namespace PKHeX.Core +namespace PKHeX.Core { /// /// class with values from Generation 2 games. @@ -15,7 +13,7 @@ namespace PKHeX.Core return; Data = data; - TMHM = GetBits(Data.Skip(0x18).Take(0x8).ToArray()); + TMHM = GetBits(Data, 0x18, 0x8); } public override byte[] Write() { diff --git a/PKHeX.Core/PersonalInfo/PersonalInfoG4.cs b/PKHeX.Core/PersonalInfo/PersonalInfoG4.cs index eb14e2b21..0c82aff76 100644 --- a/PKHeX.Core/PersonalInfo/PersonalInfoG4.cs +++ b/PKHeX.Core/PersonalInfo/PersonalInfoG4.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; namespace PKHeX.Core { @@ -16,7 +15,7 @@ namespace PKHeX.Core Data = data; // Unpack TMHM & Tutors - TMHM = GetBits(Data.Skip(0x1C).Take(0x0D).ToArray()); + TMHM = GetBits(Data, 0x1C, 0x0D); TypeTutors = new bool[0]; // not stored in personal } public override byte[] Write() diff --git a/PKHeX.Core/PersonalInfo/PersonalInfoORAS.cs b/PKHeX.Core/PersonalInfo/PersonalInfoORAS.cs index 91d237e1d..c05ca85d1 100644 --- a/PKHeX.Core/PersonalInfo/PersonalInfoORAS.cs +++ b/PKHeX.Core/PersonalInfo/PersonalInfoORAS.cs @@ -1,6 +1,4 @@ -using System.Linq; - -namespace PKHeX.Core +namespace PKHeX.Core { /// /// class with values from the OR & AS games. @@ -15,15 +13,15 @@ namespace PKHeX.Core Data = data; // Unpack TMHM & Tutors - TMHM = GetBits(Data.Skip(0x28).Take(0x10).ToArray()); - TypeTutors = GetBits(Data.Skip(0x38).Take(0x4).ToArray()); + TMHM = GetBits(Data, 0x28, 0x10); + TypeTutors = GetBits(Data, 0x38, 0x4); // 0x3C-0x40 unknown SpecialTutors = new[] { - GetBits(Data.Skip(0x40).Take(0x04).ToArray()), - GetBits(Data.Skip(0x44).Take(0x04).ToArray()), - GetBits(Data.Skip(0x48).Take(0x04).ToArray()), - GetBits(Data.Skip(0x4C).Take(0x04).ToArray()), + GetBits(Data, 0x40, 0x04), + GetBits(Data, 0x44, 0x04), + GetBits(Data, 0x48, 0x04), + GetBits(Data, 0x4C, 0x04), }; } public override byte[] Write() diff --git a/PKHeX.Core/PersonalInfo/PersonalInfoSM.cs b/PKHeX.Core/PersonalInfo/PersonalInfoSM.cs index ef32c79d1..c8bbe1cf0 100644 --- a/PKHeX.Core/PersonalInfo/PersonalInfoSM.cs +++ b/PKHeX.Core/PersonalInfo/PersonalInfoSM.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; namespace PKHeX.Core { @@ -15,12 +14,12 @@ namespace PKHeX.Core return; Data = data; - TMHM = GetBits(Data.Skip(0x28).Take(0x10).ToArray()); // 36-39 - TypeTutors = GetBits(Data.Skip(0x38).Take(0x4).ToArray()); // 40 + TMHM = GetBits(Data, 0x28, 0x10); // 36-39 + TypeTutors = GetBits(Data, 0x38, 0x4); // 40 SpecialTutors = new[] { - GetBits(Data.Skip(0x3C).Take(0x0A).ToArray()), + GetBits(Data, 0x3C, 0x0A), }; } public override byte[] Write() diff --git a/PKHeX.Core/PersonalInfo/PersonalInfoXY.cs b/PKHeX.Core/PersonalInfo/PersonalInfoXY.cs index 200dc50b0..eeb232c07 100644 --- a/PKHeX.Core/PersonalInfo/PersonalInfoXY.cs +++ b/PKHeX.Core/PersonalInfo/PersonalInfoXY.cs @@ -1,6 +1,4 @@ -using System.Linq; - -namespace PKHeX.Core +namespace PKHeX.Core { /// /// class with values from the X & Y games. @@ -16,8 +14,8 @@ namespace PKHeX.Core Data = data; // Unpack TMHM & Tutors - TMHM = GetBits(Data.Skip(0x28).Take(0x10).ToArray()); - TypeTutors = GetBits(Data.Skip(0x38).Take(0x4).ToArray()); + TMHM = GetBits(Data, 0x28, 0x10); + TypeTutors = GetBits(Data, 0x38, 0x4); // 0x3C-0x40 unknown } public override byte[] Write()