feat: Replaces params array with params ReadOnlySpan (#2125)

This commit is contained in:
Kamron Batman 2025-02-13 21:19:02 -08:00 • committed by GitHub
parent 90059c5e74
commit 279b10dd0f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 36 additions and 35 deletions

View file

@ -745,7 +745,7 @@ public static partial class Utility
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T RandomList<T>(params T[] list) => list.RandomElement();
public static T RandomList<T>(params ReadOnlySpan<T> list) => list.RandomElement();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T RandomElement<T>(this ReadOnlySpan<T> list) => list.Length == 0 ? default : list[Random(list.Length)];
@ -1305,15 +1305,15 @@ public static partial class Utility
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Combine<T>(this IList<T> source, params IList<T>[] arrays) =>
public static T[] Combine<T>(this IList<T> source, params ReadOnlySpan<IList<T>> arrays) =>
source.Combine(false, arrays);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] CombinePooled<T>(this IList<T> source, params IList<T>[] arrays) =>
public static T[] CombinePooled<T>(this IList<T> source, params ReadOnlySpan<IList<T>> arrays) =>
source.Combine(true, arrays);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T[] Combine<T>(this IList<T> source, bool pooled, params IList<T>[] arrays)
public static T[] Combine<T>(this IList<T> source, bool pooled, params ReadOnlySpan<IList<T>> arrays)
{
var totalLength = source.Count;
foreach (var arr in arrays)