dotnet/roslyn

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

Open

#73 110 ouverte le 19 avr. 2024

Voir sur GitHub
 (5 commentaires) (0 réactions) (0 assignés)C# (4 257 forks)batch import
Area-CompilersCode Gen QualityFeature - Collection Expressionshelp wanted

Métriques du dépôt

Stars
 (20 414 stars)
Métriques de merge PR
 (Merge moyen 6j 17h) (256 PRs mergées en 30 j)

Description

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);


Guide contributeur