mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-10 14:44:24 +00:00
Minor initialization tweaks
GameStrings: 10% of strings are unique; just mark everything. Stop a little early so we don't process the empty & (trade) string. LearnsetReader: All empty entries are length==0; malformed should throw an exception (never). EggMoves: Compute ptr inside the array fetch loop; don't use linq. EggMoves & string shaves off 80ms of startup time according to profiling; some could be attributed to warm-up but yay more efficient.
This commit is contained in:
parent
c46c55f304
commit
c14f2a1dd1
3 changed files with 31 additions and 25 deletions
|
@ -81,7 +81,7 @@ namespace PKHeX.Core
|
|||
metGSC_00000 = Get("gsc_00000");
|
||||
|
||||
metCXD_00000 = Get("cxd_00000");
|
||||
metCXD_00000 = SanitizeMetStringsCXD(metCXD_00000);
|
||||
SanitizeMetStringsCXD(metCXD_00000);
|
||||
|
||||
// Current Generation strings
|
||||
natures = Util.GetNaturesList(l);
|
||||
|
@ -154,18 +154,16 @@ namespace PKHeX.Core
|
|||
Get("mail4").CopyTo(g4items, 137);
|
||||
}
|
||||
|
||||
private static string[] SanitizeMetStringsCXD(string[] cxd)
|
||||
private static void SanitizeMetStringsCXD(string[] cxd)
|
||||
{
|
||||
// Mark duplicate locations with their index
|
||||
var metSanitize = (string[])cxd.Clone();
|
||||
for (int i = 0; i < metSanitize.Length; i++)
|
||||
// Less than 10% of met location values are unique.
|
||||
// Just mark them with the ID if they aren't empty.
|
||||
for (int i = 0; i < 227; i++)
|
||||
{
|
||||
var met = metSanitize[i];
|
||||
if (cxd.Count(z => z == met) > 1)
|
||||
metSanitize[i] += $" [{i:000}]";
|
||||
var str = cxd[i];
|
||||
if (str.Length != 0)
|
||||
cxd[i] = $"{str} [{i:000}]";
|
||||
}
|
||||
|
||||
return metSanitize;
|
||||
}
|
||||
|
||||
private void Sanitize()
|
||||
|
|
|
@ -60,7 +60,7 @@ namespace PKHeX.Core
|
|||
/// <remarks>Count of moves, followed by Moves and Levels which are 16-bit</remarks>
|
||||
private static Learnset ReadLearnset16(byte[] data)
|
||||
{
|
||||
if (data.Length < 4 || data.Length % 4 != 0)
|
||||
if (data.Length == 0)
|
||||
return EMPTY;
|
||||
var Count = (data.Length / 4) - 1;
|
||||
var Moves = new int[Count];
|
||||
|
|
|
@ -12,22 +12,30 @@ namespace PKHeX.Core
|
|||
|
||||
public sealed class EggMoves2 : EggMoves
|
||||
{
|
||||
private EggMoves2(byte[] data) : base(data.Select(i => (int)i).ToArray()) { }
|
||||
private EggMoves2(int[] moves) : base(moves) { }
|
||||
|
||||
public static EggMoves[] GetArray(byte[] data, int count)
|
||||
public static EggMoves2[] GetArray(byte[] data, int count)
|
||||
{
|
||||
int[] ptrs = new int[count+1];
|
||||
int baseOffset = (data[1] << 8 | data[0]) - (count * 2);
|
||||
for (int i = 1; i < ptrs.Length; i++)
|
||||
{
|
||||
var ofs = (i - 1) * 2;
|
||||
ptrs[i] = (data[ofs + 1] << 8 | data[ofs]) - baseOffset;
|
||||
}
|
||||
var entries = new EggMoves2[count + 1];
|
||||
var empty = entries[0] = new EggMoves2(Array.Empty<int>());
|
||||
|
||||
EggMoves[] entries = new EggMoves[count + 1];
|
||||
entries[0] = new EggMoves2(Array.Empty<byte>());
|
||||
int baseOffset = BitConverter.ToInt16(data, 0) - (count * 2);
|
||||
for (int i = 1; i < entries.Length; i++)
|
||||
entries[i] = new EggMoves2(data.Skip(ptrs[i]).TakeWhile(b => b != 0xFF).ToArray());
|
||||
{
|
||||
int start = BitConverter.ToInt16(data, (i - 1) * 2) - baseOffset;
|
||||
int end = Array.FindIndex(data, start, z => z == 0xFF);
|
||||
if (start == end)
|
||||
{
|
||||
entries[i] = empty;
|
||||
continue;
|
||||
}
|
||||
|
||||
int[] moves = new int[end - start];
|
||||
for (int m = start; m < end; m++)
|
||||
moves[m - start] = data[m];
|
||||
|
||||
entries[i] = new EggMoves2(moves);
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
@ -41,7 +49,7 @@ namespace PKHeX.Core
|
|||
|
||||
private static EggMoves6 Get(byte[] data)
|
||||
{
|
||||
if (data.Length < 2 || data.Length % 2 != 0)
|
||||
if (data.Length == 0)
|
||||
return None;
|
||||
|
||||
int count = BitConverter.ToInt16(data, 0);
|
||||
|
@ -69,7 +77,7 @@ namespace PKHeX.Core
|
|||
|
||||
private static EggMoves7 Get(byte[] data)
|
||||
{
|
||||
if (data.Length < 2 || data.Length % 2 != 0)
|
||||
if (data.Length == 0)
|
||||
return None;
|
||||
|
||||
int formIndex = BitConverter.ToInt16(data, 0);
|
||||
|
|
Loading…
Reference in a new issue