-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Use Linq helpers. #79775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Linq helpers. #79775
Conversation
| Contract.ThrowIfNull(TypeToGenerateIn); | ||
| var typeParametersNames = TypeToGenerateIn.GetAllTypeParameters().Select(t => t.Name).ToImmutableArray(); | ||
| var typeParametersNames = TypeToGenerateIn.GetAllTypeParameters().SelectAsArray(t => t.Name); | ||
| var parameterNames = GetParameterNames(_arguments, typeParametersNames, cancellationToken); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Select+ToImmutableArray becomes SelectAsArray.
| .GroupBy(diagnostic => diagnostic.Location.SourceTree) | ||
| .Where(group => group.Key is not null) | ||
| .SelectAsArray(group => (id: solution.GetRequiredDocument(group.Key!).Id, diagnostics: group.ToImmutableArray())); | ||
| .SelectAsArray(group => group.Key is not null, group => (id: solution.GetRequiredDocument(group.Key!).Id, diagnostics: group.ToImmutableArray())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where+SelectAsArray becomes SelectAsArray (with predicate passed to the latter).
|
|
||
| builder = ArrayBuilder<TResult>.GetInstance(); | ||
| return true; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optimized a bunch of these helpers if the count can be determined (fast path to returning empty array, and also properly sizing the dest buffer).
| .Select(p => semanticModel.GetRequiredDeclaredSymbol(p, cancellationToken)) | ||
| .Where(p => p.RefKind == RefKind.Out) | ||
| .ToImmutableArray(); | ||
| .WhereAsArray(p => p.RefKind == RefKind.Out); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where+ToImmutableArray becomes WhereAsArray
| public static T[] AsArray<T>(this IEnumerable<T> source) | ||
| => source as T[] ?? source.ToArray(); | ||
|
|
||
| public static ImmutableArray<TResult> SelectAsArray<TSource, TResult>(this IEnumerable<TSource>? source, Func<TSource, TResult> selector) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extensions that work on null receiver are odd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't disagree. however, a lot of collect/ienumrable methods do this. so this is keeping things mostly consistent. would prefer to not rock the boat there for now.
src/Features/Core/Portable/SignatureHelp/SignatureHelpService.cs
Outdated
Show resolved
Hide resolved
...t.CodeAnalysis.LanguageServer/HostWorkspace/ProjectTelemetry/ProjectLoadTelemetryReporter.cs
Show resolved
Hide resolved
|
@tmat ptal. |
| } | ||
|
|
||
| #if NET | ||
| if (source.TryGetNonEnumeratedCount(out var count)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we reasonably optimize further if the count is < 4, using TemporaryArray?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems hard to do in a generalized fashion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or, put another way. can i postpone that till later. i'd rather get this in and focus on other stuff for now.
No description provided.