mirror of
https://github.com/kwsch/PKHeX
synced 2025-02-17 05:48:44 +00:00
Remove unnecessary comparison
in Array.Resize, an array is only created if the size is not equivalent we're just repeating the same logic; let the jit optimize out the null check
This commit is contained in:
parent
40ce63873d
commit
9f20aa2f4f
2 changed files with 10 additions and 11 deletions
|
@ -22,17 +22,10 @@ namespace PKHeX.Core
|
|||
public int Box { get; set; } = -1; // Batch Editor
|
||||
public int Slot { get; set; } = -1; // Batch Editor
|
||||
|
||||
public virtual byte[] EncryptedPartyData => Truncate(Encrypt(), SIZE_PARTY);
|
||||
public virtual byte[] EncryptedBoxData => Truncate(Encrypt(), SIZE_STORED);
|
||||
public virtual byte[] DecryptedPartyData => Truncate(Write(), SIZE_PARTY);
|
||||
public virtual byte[] DecryptedBoxData => Truncate(Write(), SIZE_STORED);
|
||||
|
||||
private static byte[] Truncate(byte[] data, int newSize)
|
||||
{
|
||||
if (data.Length != newSize)
|
||||
Array.Resize(ref data, newSize);
|
||||
return data;
|
||||
}
|
||||
public virtual byte[] EncryptedPartyData => ArrayUtil.Truncate(Encrypt(), SIZE_PARTY);
|
||||
public virtual byte[] EncryptedBoxData => ArrayUtil.Truncate(Encrypt(), SIZE_STORED);
|
||||
public virtual byte[] DecryptedPartyData => ArrayUtil.Truncate(Write(), SIZE_PARTY);
|
||||
public virtual byte[] DecryptedBoxData => ArrayUtil.Truncate(Write(), SIZE_STORED);
|
||||
|
||||
public virtual bool Valid { get => ChecksumValid && Sanity == 0; set { if (!value) return; Sanity = 0; RefreshChecksum(); } }
|
||||
|
||||
|
|
|
@ -21,6 +21,12 @@ namespace PKHeX.Core
|
|||
return true;
|
||||
}
|
||||
|
||||
public static byte[] Truncate(byte[] data, int newSize)
|
||||
{
|
||||
Array.Resize(ref data, newSize);
|
||||
return data;
|
||||
}
|
||||
|
||||
public static byte[] Slice(this byte[] src, int offset, int length)
|
||||
{
|
||||
byte[] data = new byte[length];
|
||||
|
|
Loading…
Add table
Reference in a new issue