timcassell / ProtoPromise

Robust and efficient library for management of asynchronous operations in C#/.Net.
MIT License
145 stars 13 forks source link

Add overloads that accept `Span<T>` parameter #332

Closed timcassell closed 5 months ago

timcassell commented 7 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

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.

(And maybe in C#13 we can make that params Span<T> also.)

[Edit] Or ReadOnlySpan<T> since we only read the values.