dotnet/roslyn

Generalize `(CollectionBuilderType<T>)[..readOnlySpan]` optimization to spread operands which are implicitly convertible to `ReadOnlySpan<T>`

Open

#73.110 aperta il 19 apr 2024

Vedi su GitHub
 (5 commenti) (0 reazioni) (0 assegnatari)C# (4257 fork)batch import
Area-CompilersCode Gen QualityFeature - Collection Expressionshelp wanted

Metriche repository

Star
 (20.414 star)
Metriche merge PR
 (Merge medio 6g 17h) (256 PR mergiate in 30 g)

Descrizione

I would welcome a follow-up PR which also handles cases where the spread operand is implicitly convertible to ReadOnlySpan<T>.

Originally posted by @RikkiGibson in https://github.com/dotnet/roslyn/issues/73102#issuecomment-2067272169

Affected scenarios would include:

Span<int> span = ..;
MyCollectionBuilderType<T> collection = [..span];

// currently:
MyCollectionBuilderType<T> collection = MyCollectionBuilderType.Create((ReadOnlySpan<T>)span.ToArray());

// could change to:
MyCollectionBuilderType<T> collection = MyCollectionBuilderType.Create((ReadOnlySpan<T>)span);


Guida contributor