Add misc generic constraints

Resolves some allocation analyzer issues
This commit is contained in:
Kurt
2023-03-25 23:23:43 -07:00
parent 0087ccb44f
commit aa13c93e65
7 changed files with 11 additions and 10 deletions

View File

@@ -1,9 +1,9 @@
using System;
using System;
using static PKHeX.Core.GameVersion;
namespace PKHeX.Core;
public sealed class EventWorkspace<TSave, TWork> where TSave : IEventFlagArray, IEventWorkArray<TWork> where TWork : unmanaged
public sealed class EventWorkspace<TSave, TWork> where TSave : class, IEventFlagArray, IEventWorkArray<TWork> where TWork : unmanaged
{
private readonly TSave SAV;
public readonly bool[] Flags;

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using static PKHeX.Core.EventWorkDiffCompatibility;
@@ -9,7 +9,7 @@ namespace PKHeX.Core;
/// <summary>
/// Calculates differences in the Event Blocks between two <see cref="SaveFile"/>.
/// </summary>
public sealed class EventBlockDiff<T, T2> : IEventWorkDiff where T : IEventFlagArray, IEventWorkArray<T2> where T2 : unmanaged, IEquatable<T2>
public sealed class EventBlockDiff<T, T2> : IEventWorkDiff where T : class, IEventFlagArray, IEventWorkArray<T2> where T2 : unmanaged, IEquatable<T2>
{
public List<int> SetFlags { get; } = new();
public List<int> ClearedFlags { get; } = new();

View File

@@ -6,7 +6,7 @@ namespace PKHeX.Core;
/// Tuple containing data for a <see cref="Slot"/> and the originating <see cref="View"/>
/// </summary>
/// <typeparam name="T"></typeparam>
public sealed class SlotViewInfo<T> : IEquatable<T>
public sealed class SlotViewInfo<T> : IEquatable<T> where T : class
{
public readonly ISlotInfo Slot;
public readonly ISlotViewer<T> View;

View File

@@ -194,6 +194,7 @@ private static void GetSuggestedRelearnEgg(this IEncounterTemplate enc, ReadOnly
private static void GetEggRelearnMoves(this IEncounterTemplate enc, ReadOnlySpan<MoveResult> parse, PKM pk, Span<ushort> moves)
{
pk.GetRelearnMoves(moves);
// Extract a list of the moves that should end up in the relearn move list.
LoadRelearnFlagged(moves, parse, pk);

View File

@@ -105,7 +105,7 @@ public static bool IsAbilityPatchRevertPossible(EvolutionHistory evosAll, int ab
private static bool IsCapsulePossible<TTable, TInfo>(EvoCriteria[] evos, TTable table)
where TTable : IPersonalTable<TInfo>
where TInfo : IPersonalInfo, IPersonalAbility12
where TInfo : class, IPersonalInfo, IPersonalAbility12
{
for (int i = evos.Length - 1; i >= 0; i--)
{
@@ -119,7 +119,7 @@ public static bool IsAbilityPatchRevertPossible(EvolutionHistory evosAll, int ab
private static bool IsPatchPossible<TTable, TInfo>(EvoCriteria[] evos, TTable table)
where TTable : IPersonalTable<TInfo>
where TInfo : IPersonalInfo, IPersonalAbility12H
where TInfo : class, IPersonalInfo, IPersonalAbility12H
{
for (int i = evos.Length - 1; i >= 0; i--)
{
@@ -144,7 +144,7 @@ public static bool IsAbilityPatchRevertPossible(EvolutionHistory evosAll, int ab
private static bool IsRevertPossible<TTable, TInfo>(EvoCriteria[] evos, TTable table, int abilityIndex)
where TTable : IPersonalTable<TInfo>
where TInfo : IPersonalInfo, IPersonalAbility12H
where TInfo : class, IPersonalInfo, IPersonalAbility12H
{
bool revert = false;
for (var i = evos.Length - 1; i >= 0; i--)

View File

@@ -58,7 +58,7 @@ protected InventoryPouch(InventoryType type, ushort[] legal, int maxCount, int o
public void SortByEmpty() => Array.Sort(Items, (x, y) => (x.Count == 0).CompareTo(y.Count == 0));
public void SortBy<TItem, TCompare>(Func<TItem, TCompare> selector) where TItem : InventoryItem where TCompare : IComparable => Array.Sort(Items, (x, y) => selector((TItem)x).CompareTo(selector((TItem)y)));
private static int Compare<TCompare>(int i1, int i2, IReadOnlyList<TCompare> n, bool rev) where TCompare : IComparable
private static int Compare<TCompare>(int i1, int i2, IReadOnlyList<TCompare> n, bool rev) where TCompare : class, IComparable
{
if (i1 == 0 || i1 >= n.Count)
return 1;

View File

@@ -2,7 +2,7 @@
namespace PKHeX.WinForms.Controls;
public sealed class SlotChangeInfo<TCursor, TImageSource> where TCursor : class
public sealed class SlotChangeInfo<TCursor, TImageSource> where TCursor : class where TImageSource : class
{
public bool LeftMouseIsDown { get; set; }
public bool DragDropInProgress { get; set; }