dotnet/roslyn

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

Open

#73,110 opened on 2024年4月19日

GitHub で見る
 (5 comments) (0 reactions) (0 assignees)C# (4,257 forks)batch import
Area-CompilersCode Gen QualityFeature - Collection Expressionshelp wanted

Repository metrics

Stars
 (20,414 stars)
PR merge metrics
 (平均マージ 6d 17h) (30d で 256 merged PRs)

説明

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


コントリビューターガイド