Skip to content

Conversation

@CyrusNajmabadi
Copy link
Member

No description provided.

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);
Copy link
Member Author

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()));
Copy link
Member Author

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;
}
Copy link
Member Author

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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where+ToImmutableArray becomes WhereAsArray

@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review August 5, 2025 11:06
@CyrusNajmabadi CyrusNajmabadi requested review from a team as code owners August 5, 2025 11:06
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)
Copy link
Member

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.

Copy link
Member Author

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.

@CyrusNajmabadi CyrusNajmabadi requested a review from tmat August 6, 2025 10:36
@CyrusNajmabadi
Copy link
Member Author

@tmat ptal.

}

#if NET
if (source.TryGetNonEnumeratedCount(out var count))
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

@CyrusNajmabadi CyrusNajmabadi requested a review from tmat August 6, 2025 20:23
@CyrusNajmabadi CyrusNajmabadi merged commit 4524dbf into main Aug 6, 2025
28 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the selectAsArray branch August 6, 2025 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants