Closed timcassell closed 5 months ago
Now that C# 12 has added collection literals, it's super easy to create a span with known size. For all functions that currently accept params T[], we can add an overload that accepts Span<T>. This way you can save on array allocations by changing
params T[]
Span<T>
Promise.All(promise1, promise2, promise3, promise4, promise5)
to
Promise.All([promise1, promise2, promise3, promise4, promise5])
And the compiler will just use the more efficient Span overload.
Span
(And maybe in C#13 we can make that params Span<T> also.)
params Span<T>
[Edit] Or ReadOnlySpan<T> since we only read the values.
ReadOnlySpan<T>
Now that C# 12 has added collection literals, it's super easy to create a span with known size. For all functions that currently accept
params T[]
, we can add an overload that acceptsSpan<T>
. This way you can save on array allocations by changingto
And the compiler will just use the more efficient
Span
overload.(And maybe in C#13 we can make that
params Span<T>
also.)[Edit] Or
ReadOnlySpan<T>
since we only read the values.