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; using static PKHeX.Core.GameVersion;
namespace PKHeX.Core; 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; private readonly TSave SAV;
public readonly bool[] Flags; public readonly bool[] Flags;

View file

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using static PKHeX.Core.EventWorkDiffCompatibility; using static PKHeX.Core.EventWorkDiffCompatibility;
@ -9,7 +9,7 @@ namespace PKHeX.Core;
/// <summary> /// <summary>
/// Calculates differences in the Event Blocks between two <see cref="SaveFile"/>. /// Calculates differences in the Event Blocks between two <see cref="SaveFile"/>.
/// </summary> /// </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> SetFlags { get; } = new();
public List<int> ClearedFlags { 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"/> /// Tuple containing data for a <see cref="Slot"/> and the originating <see cref="View"/>
/// </summary> /// </summary>
/// <typeparam name="T"></typeparam> /// <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 ISlotInfo Slot;
public readonly ISlotViewer<T> View; public readonly ISlotViewer<T> View;

View file

@ -194,6 +194,7 @@ public static class MoveListSuggest
private static void GetEggRelearnMoves(this IEncounterTemplate enc, ReadOnlySpan<MoveResult> parse, PKM pk, Span<ushort> moves) 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. // Extract a list of the moves that should end up in the relearn move list.
LoadRelearnFlagged(moves, parse, pk); LoadRelearnFlagged(moves, parse, pk);

View file

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

View file

@ -58,7 +58,7 @@ public abstract class InventoryPouch
public void SortByEmpty() => Array.Sort(Items, (x, y) => (x.Count == 0).CompareTo(y.Count == 0)); 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))); 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) if (i1 == 0 || i1 >= n.Count)
return 1; return 1;

View file

@ -2,7 +2,7 @@ using PKHeX.Core;
namespace PKHeX.WinForms.Controls; 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 LeftMouseIsDown { get; set; }
public bool DragDropInProgress { get; set; } public bool DragDropInProgress { get; set; }