mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-10 14:44:24 +00:00
Use span if possible instead of new arrays
This commit is contained in:
parent
01f1be6f89
commit
9bddc89c07
4 changed files with 10 additions and 10 deletions
|
@ -8,11 +8,11 @@ namespace PKHeX.Core
|
|||
public sealed class PokeList1 : PokeListGB<PK1>
|
||||
{
|
||||
protected override byte GetSpeciesBoxIdentifier(PK1 pk) => SpeciesConverter.SetG1Species(pk.Species);
|
||||
protected override PK1 GetEntry(byte[] dat, byte[] otname, byte[] nick, bool egg)
|
||||
protected override PK1 GetEntry(byte[] dat, ReadOnlySpan<byte> otname, ReadOnlySpan<byte> nick, bool egg)
|
||||
{
|
||||
var result = new PK1(dat, Japanese); // no eggs
|
||||
otname.AsSpan().CopyTo(result.OT_Trash);
|
||||
nick.AsSpan().CopyTo(result.Nickname_Trash);
|
||||
otname.CopyTo(result.OT_Trash);
|
||||
nick.CopyTo(result.Nickname_Trash);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,11 +8,11 @@ namespace PKHeX.Core
|
|||
public sealed class PokeList2 : PokeListGB<PK2>
|
||||
{
|
||||
protected override byte GetSpeciesBoxIdentifier(PK2 pk) => pk.IsEgg ? PK2.EggSpeciesValue : (byte)pk.Species;
|
||||
protected override PK2 GetEntry(byte[] dat, byte[] otname, byte[] nick, bool egg)
|
||||
protected override PK2 GetEntry(byte[] dat, ReadOnlySpan<byte> otname, ReadOnlySpan<byte> nick, bool egg)
|
||||
{
|
||||
var result = new PK2(dat, Japanese) { IsEgg = egg };
|
||||
otname.AsSpan().CopyTo(result.OT_Trash);
|
||||
nick.AsSpan().CopyTo(result.Nickname_Trash);
|
||||
otname.CopyTo(result.OT_Trash);
|
||||
nick.CopyTo(result.Nickname_Trash);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ namespace PKHeX.Core
|
|||
|
||||
protected abstract int GetEntrySize();
|
||||
protected abstract byte GetSpeciesBoxIdentifier(T pk);
|
||||
protected abstract T GetEntry(byte[] dat, byte[] otname, byte[] nick, bool egg);
|
||||
protected abstract T GetEntry(byte[] dat, ReadOnlySpan<byte> otname, ReadOnlySpan<byte> nick, bool egg);
|
||||
|
||||
public T this[int i]
|
||||
{
|
||||
|
@ -141,8 +141,8 @@ namespace PKHeX.Core
|
|||
int nkOfs = GetOffsetPKMNickname(base_ofs, index);
|
||||
|
||||
var dat = Data.Slice(pkOfs, Entry_Size);
|
||||
var otname = Data.Slice(otOfs, StringLength);
|
||||
var nick = Data.Slice(nkOfs, StringLength);
|
||||
var otname = Data.AsSpan(otOfs, StringLength);
|
||||
var nick = Data.AsSpan(nkOfs, StringLength);
|
||||
|
||||
return GetEntry(dat, otname, nick, Data[1 + index] == 0xFD);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace PKHeX.Core
|
|||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
public static byte[] Slice(this byte[] src, int offset, int length) => src.AsSpan(offset, length).ToArray();
|
||||
public static byte[] SliceEnd(this byte[] src, int offset) => src.AsSpan(offset).ToArray();
|
||||
public static T[] Slice<T>(this T[] src, int offset, int length) => src.AsSpan(offset, length).ToArray();
|
||||
|
|
Loading…
Reference in a new issue