Clean up TagHelperFactsService and friends #9199
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change cleans up the tooling layer's
TagHelperFactsService
to consume and returnImmutableArray<T>
rather thanIReadOnlyList<T>
. I've gone through all code using this service to ensure that any boxing is removed or eliminated. I also eliminated several other allocations (e.g..ToList().AsReadOnly()
).@dotnet/razor-compiler: I made a couple of changes to compiler code to facilitate the shift over to
ImmutableArray<T>
:TagHelperParseTreeRewriter
which previously held onto aList<KeyValuePair<string, string>>
, which it handed out during tag helper binding before reusing the same collection later. In this change, it holds onto anImmutableArray<KeyValuePair<string, string>>.Builder
and returns aImmutableArray<KeyValuePair<string, string>>
. So, this represents a new allocation (for the underlying array) and copy that wasn't there before. However, I don't expect this will be significant and the code is simpler and a bit less surprising now.TagHelperMatchingConventions.SatsifiesAttributes(...)
. IMO, this makes the code a bit more readable and takes advantage of the fact thatImmutableArray<T>
is now in play, so it can foreach.In Shared.Utilities, I made a few tweaks that I hope will be useful:
PooledArrayBuilder<T>
now has an enumerator.KeyValuePair.Create(...)
helper for NetFx and netstandard2.0, similar to the one on core.HashSet<T>.AddRange(...)
extension method to avoid boxing when passing anImmutableArray<T>
. Note: This is named differently that thanHashSet<T>.UnionWith(...)
, which would normally be used to add multiple items to a hash set. SinceUnionWith
already exists as an instance method, the compiler won't consider similar extension methods of the same name when performing overload resolution.