Minor perf improvements

This commit is contained in:
Kurt 2021-05-10 01:01:45 -07:00
parent 8e9953dc0f
commit d340642b09
6 changed files with 25 additions and 16 deletions

View file

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace PKHeX.Core
{
@ -198,8 +197,8 @@ namespace PKHeX.Core
int newHC = BigEndian.ToInt32(data, start + subOffsets[0] + 0x38);
bool header = newHC == oldHC;
var oldCHK = Data.Skip(0x10).Take(0x10);
var newCHK = data.Skip(0x10).Take(0x10);
var oldCHK = Data.AsSpan(0x10, 0x10);
var newCHK = data.AsSpan(0x10, 0x10);
bool body = newCHK.SequenceEqual(oldCHK);
return $"Header Checksum {(header ? "V" : "Inv")}alid, Body Checksum {(body ? "V" : "Inv")}alid.";
}
@ -221,13 +220,17 @@ namespace PKHeX.Core
BigEndian.GetBytes(newHC).CopyTo(data, start + subOffset0 + 0x38);
// Body Checksum
new byte[16].CopyTo(data, 0x10); // Clear old Checksum Data
data.AsSpan(0x10, 0x10).Fill(0); // Clear old Checksum Data
uint[] checksum = new uint[4];
int dt = 8;
for (int i = 0; i < 4; i++)
for (int i = 0; i < checksum.Length; i++)
{
for (int j = 0; j < 0x9FF4; j += 2, dt += 2)
checksum[i] += BigEndian.ToUInt16(data, dt);
uint val = 0;
var end = dt + 0x9FF4;
for (int j = dt; j < end; j += 2)
val += BigEndian.ToUInt16(data, j);
dt = end;
checksum[i] = val;
}
ushort[] newchks = new ushort[8];

View file

@ -29,13 +29,20 @@ namespace PKHeX.Core
public PokeListHeader(SAV7b sav, int offset) : base(sav)
{
Offset = offset;
PokeListInfo = LoadPointerData();
var info = PokeListInfo = LoadPointerData();
if (!sav.State.Exportable)
{
for (int i = 0; i < COUNT; i++)
PokeListInfo[i] = SLOT_EMPTY;
info[i] = SLOT_EMPTY;
}
else
{
for (int i = 0; i < 6; i++)
{
if (info[i] < MAX_SLOTS)
++_partyCount;
}
}
PartyCount = PokeListInfo.Take(6).Count(z => z < MAX_SLOTS);
}
private int _partyCount;

View file

@ -552,7 +552,7 @@ namespace PKHeX.WinForms.Controls
{
ChangingFields = true;
CB_HPType.InitializeBinding();
CB_HPType.DataSource = Util.GetCBList(GameInfo.Strings.types.Skip(1).Take(16).ToArray());
CB_HPType.DataSource = Util.GetCBList(GameInfo.Strings.types.AsSpan(1, 16));
ChangingFields = false;
}

View file

@ -43,13 +43,13 @@ namespace PKHeX.WinForms
switch (SAV.Generation)
{
case 3 when SAV is SAV3:
CB_BG.Items.AddRange(GameInfo.Strings.wallpapernames.Take(16).ToArray());
CB_BG.Items.AddRange(GameInfo.Strings.wallpapernames.Slice(0, 16));
return true;
case 4 or 5 or 6:
CB_BG.Items.AddRange(GameInfo.Strings.wallpapernames);
return true;
case 7:
CB_BG.Items.AddRange(GameInfo.Strings.wallpapernames.Take(16).ToArray());
CB_BG.Items.AddRange(GameInfo.Strings.wallpapernames.Slice(0, 16));
return true;
case 8:
CB_BG.Items.AddRange(Enumerable.Range(1, 19).Select(z => $"Wallpaper {z}").ToArray());

View file

@ -419,7 +419,7 @@ namespace PKHeX.WinForms
return;
int offset = LB_DataEntry.SelectedIndex * 0x1B4;
var nicktrash = data.Skip(offset + 0x18).Take(24).ToArray();
var nicktrash = data.Slice(offset + 0x18, 24);
SAV.SetString(TB_Nickname.Text, 12).CopyTo(nicktrash, 0);
var d = new TrashEditor(tb, nicktrash, SAV);
d.ShowDialog();

View file

@ -1,5 +1,4 @@
using System;
using System.Linq;
using System.Windows.Forms;
using PKHeX.Core;
@ -20,7 +19,7 @@ namespace PKHeX.WinForms
// Cell Data @ 0x1D8C
// Use constants 0x18C/2 = 198 thru +95
ushort[] constants = SAV.GetEventConsts();
ushort[] cells = constants.Skip(celloffset).Take(CellCount).ToArray();
ushort[] cells = constants.Slice(celloffset, CellCount);
int cellCount = constants[cellstotal];
int cellCollected = constants[cellscollected];