mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-09-08 21:45:56 -05: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:
@@ -22,17 +22,10 @@ public abstract class PKM : ITrainerID, ILangNick, IGameValueLimit, INature
|
||||
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 @@ public static class ArrayUtil
|
||||
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];
|
||||
|
||||
Reference in New Issue
Block a user