mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 04:23:12 +00:00
Use ReadOnlySpan instead of Span if appropriate
This commit is contained in:
parent
600c8f704f
commit
0093927e15
12 changed files with 24 additions and 24 deletions
|
@ -97,7 +97,7 @@ public static class MoveShopRecordApplicator
|
|||
shop.SetMasteredRecordFlag(index, true);
|
||||
}
|
||||
|
||||
public static void SetEncounterMasteryFlags(this IMoveShop8Mastery shop, Span<int> moves, Learnset mastery, int level)
|
||||
public static void SetEncounterMasteryFlags(this IMoveShop8Mastery shop, ReadOnlySpan<int> moves, Learnset mastery, int level)
|
||||
{
|
||||
var possible = shop.MoveShopPermitIndexes;
|
||||
var permit = shop.MoveShopPermitFlags;
|
||||
|
|
|
@ -86,7 +86,7 @@ namespace PKHeX.Core
|
|||
/// </summary>
|
||||
/// <param name="pk">Pokémon to modify.</param>
|
||||
/// <param name="moves">Moves to apply.</param>
|
||||
public static ModifyResult SetMoves(PKM pk, Span<int> moves)
|
||||
public static ModifyResult SetMoves(PKM pk, ReadOnlySpan<int> moves)
|
||||
{
|
||||
pk.SetMoves(moves);
|
||||
pk.HealPP();
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace PKHeX.Core
|
|||
/// <param name="pk"></param>
|
||||
/// <param name="h">History of evolutions present as</param>
|
||||
/// <param name="IVs"><see cref="PKM.IVs"/> to use (if already known). Will fetch the current <see cref="PKM.IVs"/> if not provided.</param>
|
||||
public static void SetSuggestedHyperTrainingData(this PKM pk, EvolutionHistory h, Span<int> IVs)
|
||||
public static void SetSuggestedHyperTrainingData(this PKM pk, EvolutionHistory h, ReadOnlySpan<int> IVs)
|
||||
{
|
||||
if (pk is not IHyperTrain t)
|
||||
return;
|
||||
|
@ -83,7 +83,7 @@ namespace PKHeX.Core
|
|||
pb.ResetCP();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="SetSuggestedHyperTrainingData(PKM,EvolutionHistory,Span{int})"/>
|
||||
/// <inheritdoc cref="SetSuggestedHyperTrainingData(PKM,EvolutionHistory,ReadOnlySpan{int})"/>
|
||||
public static void SetSuggestedHyperTrainingData(this PKM pk, int[]? IVs = null) => pk.SetSuggestedHyperTrainingData(EvolutionHistory.Empty, IVs ?? pk.IVs);
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace PKHeX.Core
|
|||
|
||||
public string Summary => $"{ID:00}: {Offset:X5}-{Offset + Length - 1:X5}, {Length:X5}";
|
||||
|
||||
protected abstract bool ChecksumValid(Span<byte> data);
|
||||
protected abstract bool ChecksumValid(ReadOnlySpan<byte> data);
|
||||
protected abstract void SetChecksum(Span<byte> data);
|
||||
|
||||
/// <summary>
|
||||
|
@ -21,7 +21,7 @@ namespace PKHeX.Core
|
|||
/// <param name="blocks">Block info objects used for offset/length</param>
|
||||
/// <param name="data">Complete data array</param>
|
||||
/// <returns>True if checksums are valid, false if anything is invalid.</returns>
|
||||
public static bool GetChecksumsValid(IEnumerable<BlockInfo> blocks, Span<byte> data)
|
||||
public static bool GetChecksumsValid(IEnumerable<BlockInfo> blocks, ReadOnlySpan<byte> data)
|
||||
{
|
||||
foreach (var b in blocks)
|
||||
{
|
||||
|
|
|
@ -32,9 +32,9 @@ namespace PKHeX.Core
|
|||
}
|
||||
|
||||
private int ChecksumOffset => BlockInfoOffset + 0x14 + ((int)ID * 8) + 6;
|
||||
protected abstract ushort GetChecksum(Span<byte> data);
|
||||
protected abstract ushort GetChecksum(ReadOnlySpan<byte> data);
|
||||
|
||||
protected override bool ChecksumValid(Span<byte> data)
|
||||
protected override bool ChecksumValid(ReadOnlySpan<byte> data)
|
||||
{
|
||||
ushort chk = GetChecksum(data);
|
||||
var old = ReadUInt16LittleEndian(data[ChecksumOffset..]);
|
||||
|
@ -51,18 +51,18 @@ namespace PKHeX.Core
|
|||
public sealed class BlockInfo6 : BlockInfo3DS
|
||||
{
|
||||
public BlockInfo6(int bo, uint id, int ofs, int len) : base(bo, id, ofs, len) { }
|
||||
protected override ushort GetChecksum(Span<byte> data) => Checksums.CRC16_CCITT(data.Slice(Offset, Length));
|
||||
protected override ushort GetChecksum(ReadOnlySpan<byte> data) => Checksums.CRC16_CCITT(data.Slice(Offset, Length));
|
||||
}
|
||||
|
||||
public sealed class BlockInfo7 : BlockInfo3DS
|
||||
{
|
||||
public BlockInfo7(int bo, uint id, int ofs, int len) : base(bo, id, ofs, len) { }
|
||||
protected override ushort GetChecksum(Span<byte> data) => Checksums.CRC16Invert(data.Slice(Offset, Length));
|
||||
protected override ushort GetChecksum(ReadOnlySpan<byte> data) => Checksums.CRC16Invert(data.Slice(Offset, Length));
|
||||
}
|
||||
|
||||
public sealed class BlockInfo7b : BlockInfo3DS
|
||||
{
|
||||
public BlockInfo7b(int bo, uint id, int ofs, int len) : base(bo, id, ofs, len) { }
|
||||
protected override ushort GetChecksum(Span<byte> data) => Checksums.CRC16NoInvert(data.Slice(Offset, Length));
|
||||
protected override ushort GetChecksum(ReadOnlySpan<byte> data) => Checksums.CRC16NoInvert(data.Slice(Offset, Length));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,9 +19,9 @@ namespace PKHeX.Core
|
|||
ChecksumMirror = chkMirror;
|
||||
}
|
||||
|
||||
private ushort GetChecksum(Span<byte> data) => Checksums.CRC16_CCITT(data.Slice(Offset, Length));
|
||||
private ushort GetChecksum(ReadOnlySpan<byte> data) => Checksums.CRC16_CCITT(data.Slice(Offset, Length));
|
||||
|
||||
protected override bool ChecksumValid(Span<byte> data)
|
||||
protected override bool ChecksumValid(ReadOnlySpan<byte> data)
|
||||
{
|
||||
ushort chk = GetChecksum(data);
|
||||
if (chk != ReadUInt16LittleEndian(data[ChecksumOffset..]))
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace PKHeX.Core
|
|||
SaveCount = ReadUInt32BigEndian(data[(Offset + 8)..]);
|
||||
}
|
||||
|
||||
protected override bool ChecksumValid(Span<byte> data)
|
||||
protected override bool ChecksumValid(ReadOnlySpan<byte> data)
|
||||
{
|
||||
var chk = GetChecksum(data);
|
||||
var old = ReadUInt32BigEndian(data[Offset..]);
|
||||
|
@ -35,7 +35,7 @@ namespace PKHeX.Core
|
|||
WriteUInt32BigEndian(span, chk);
|
||||
}
|
||||
|
||||
private uint GetChecksum(Span<byte> data)
|
||||
private uint GetChecksum(ReadOnlySpan<byte> data)
|
||||
{
|
||||
var span = data.Slice(Offset + 4, ChecksumRegionSize);
|
||||
return Checksums.CheckSum16BigInvert(span);
|
||||
|
|
|
@ -175,11 +175,11 @@ namespace PKHeX.Core
|
|||
subkey[0xF] ^= 0x87;
|
||||
}
|
||||
|
||||
private static void Xor(ReadOnlySpan<byte> b1, ReadOnlySpan<byte> b2, Span<byte> x)
|
||||
private static void Xor(ReadOnlySpan<byte> b1, ReadOnlySpan<byte> b2, Span<byte> result)
|
||||
{
|
||||
Debug.Assert(b1.Length == b2.Length);
|
||||
for (var i = 0; i < b1.Length; i++)
|
||||
x[i] = (byte)(b1[i] ^ b2[i]);
|
||||
result[i] = (byte)(b1[i] ^ b2[i]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -44,18 +44,18 @@ public sealed class MyItem8a : MyItem
|
|||
value[1].SetPouch(access.GetBlock(SaveBlockAccessor8LA.KItemKey).Data);
|
||||
value[2].SetPouch(access.GetBlock(SaveBlockAccessor8LA.KItemStored).Data);
|
||||
value[3].SetPouch(access.GetBlock(SaveBlockAccessor8LA.KItemRecipe).Data);
|
||||
SaveFavorites(value, access);
|
||||
SaveFavorites((InventoryPouch8a[])value, access);
|
||||
}
|
||||
}
|
||||
|
||||
private static void LoadFavorites(IEnumerable<InventoryPouch8a> pouches, SCBlockAccessor access)
|
||||
private static void LoadFavorites(ReadOnlySpan<InventoryPouch8a> pouches, SCBlockAccessor access)
|
||||
{
|
||||
var favorites = access.GetBlock(SaveBlockAccessor8LA.KItemFavorite).Data.AsSpan();
|
||||
foreach (var arr in pouches)
|
||||
LoadFavorites(arr.Items, favorites);
|
||||
}
|
||||
|
||||
private static void SaveFavorites(IEnumerable<InventoryPouch> pouches, SCBlockAccessor access)
|
||||
private static void SaveFavorites(ReadOnlySpan<InventoryPouch8a> pouches, SCBlockAccessor access)
|
||||
{
|
||||
var favorites = access.GetBlock(SaveBlockAccessor8LA.KItemFavorite).Data.AsSpan();
|
||||
favorites.Clear();
|
||||
|
@ -63,7 +63,7 @@ public sealed class MyItem8a : MyItem
|
|||
SaveFavorites(arr.Items, favorites);
|
||||
}
|
||||
|
||||
private static void LoadFavorites(IEnumerable<InventoryItem> items, Span<byte> favorites)
|
||||
private static void LoadFavorites(ReadOnlySpan<InventoryItem> items, ReadOnlySpan<byte> favorites)
|
||||
{
|
||||
foreach (var z in items)
|
||||
{
|
||||
|
|
|
@ -189,7 +189,7 @@ namespace PKHeX.Core
|
|||
return result;
|
||||
}
|
||||
|
||||
internal static T[] ConcatAll<T>(T[] arr1, T[] arr2, Span<T> arr3)
|
||||
internal static T[] ConcatAll<T>(T[] arr1, T[] arr2, ReadOnlySpan<T> arr3)
|
||||
{
|
||||
int len = arr1.Length + arr2.Length + arr3.Length;
|
||||
var result = new T[len];
|
||||
|
|
|
@ -84,7 +84,7 @@ namespace PKHeX.Core
|
|||
cbList.Sort(beginCount, allowed.Length, Comparer);
|
||||
}
|
||||
|
||||
public static void AddCBWithOffset(List<ComboItem> cbList, Span<string> inStrings, int offset)
|
||||
public static void AddCBWithOffset(List<ComboItem> cbList, ReadOnlySpan<string> inStrings, int offset)
|
||||
{
|
||||
int beginCount = cbList.Count;
|
||||
cbList.Capacity += inStrings.Length;
|
||||
|
|
|
@ -196,7 +196,7 @@ namespace PKHeX.Tests.Legality.Shadow
|
|||
VerifyResultsAntiShiny(Mawile, Encounters3Teams.Mawile, 12345, 51882, stackalloc[] {31, 30, 29, 31, 23, 27});
|
||||
}
|
||||
|
||||
private static void VerifyResultsAntiShiny(ReadOnlySpan<uint> resultPIDs, TeamLock[] team, int tid, int sid, Span<int> ivs)
|
||||
private static void VerifyResultsAntiShiny(ReadOnlySpan<uint> resultPIDs, TeamLock[] team, int tid, int sid, ReadOnlySpan<int> ivs)
|
||||
{
|
||||
var pk3 = new PK3
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue