Some material shpk refactoring.

This commit is contained in:
Ottermandias 2023-02-23 17:47:59 +01:00
parent 7e56858bc6
commit ebbc3fed86
5 changed files with 754 additions and 594 deletions

View file

@ -10,4 +10,26 @@ public static class UtilityFunctions
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static T? FirstOrNull<T>(this IEnumerable<T> values, Func<T, bool> predicate) where T : struct
=> values.Cast<T?>().FirstOrDefault(v => predicate(v!.Value));
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static T[] AddItem<T>(this T[] array, T element, int count = 1)
{
var length = array.Length;
var newArray = new T[array.Length + count];
Array.Copy(array, newArray, length);
for (var i = length; i < newArray.Length; ++i)
newArray[i] = element;
return newArray;
}
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static T[] RemoveItems<T>(this T[] array, int offset, int count = 1)
{
var newArray = new T[array.Length - count];
Array.Copy(array, newArray, offset);
Array.Copy(array, offset + count, newArray, offset, newArray.Length - offset);
return newArray;
}
}