-
Notifications
You must be signed in to change notification settings - Fork 199
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
Change RazorSyntaxTree.Diagnostics from an IReadOnlyList<RazorDiagnostic> to an ImmutableArray<RazorDiagnostic> #10797
Change RazorSyntaxTree.Diagnostics from an IReadOnlyList<RazorDiagnostic> to an ImmutableArray<RazorDiagnostic> #10797
Conversation
- Use pooled `ImmutableArray<RazorDiagnostic>.Builder` internally - Don't request pooled builder until first error is added - Make ErrorSink disposable to return builder to pool - Add GetErrorsAndClear() method to returns an `ImmutableArray<RazorDiagnostic>` and clears out the sink. - Add 'ParserContext.PushNewErrorScope(...)` to handle the temporary ErrorSinks used by CSharpCodeParser
This change cleans up ParserContext a bit and uses pooled collections within it.
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.
✅ Tooling
@@ -1333,4 +1333,196 @@ private void MoveInlineItemsToBuilder() | |||
// Since _inlineCount tracks the number of inline items used, we zero it out here. | |||
_inlineCount = 0; | |||
} | |||
|
|||
public readonly ImmutableArray<T> ToImmutableOrdered() |
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.
I was looking for these methods just yesterday, and I couldn't find them, but knew I'd seem them somewhere. The mystery is solved! :D
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.
LGTM. I think every time I saw something I wanted to comment on, you fixed it in the next commit :)
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.
Thanks as always for the meticulous commit history Dustin, it significantly helps make these reviews easy. Only one small testing comment, otherwise everything LGTM.
...soft.AspNetCore.Razor.Utilities.Shared.Test/PooledObjects/PooledArrayBuilderOrderingTests.cs
Show resolved
Hide resolved
It is perfectly legal for a PooledArrayBuilder<T> to be drained via one of the DrainToImmutable* methods and then continue adding items to the builder. However, if the inner ImmutableArray<T>.Builder's capacity was set to 0 during the drain, its capacity will not be reset to any specified value when adding new items. This change fixes that.
This pull request represents several changes with the ultimate goal of exposing
RazorSyntaxTree.Diagnostics
as anImmutableArray<RazorDiagnostic>
rather than anIReadOnlyList<RazorDiagnostic>
:RazorSyntaxTree
and get rid ofDefaultRazorSyntaxTree
.(Drain)ToImmutableOrdered*
methods toPooledArrayBuilder<T>
. Note that this change also includes a refactoring to the various unit tests for ordering to share test data that I've isolated to a single commit.ErrorSink
to no longer greedily create a newList<T>
before any errors are encountered.ParserContext
and make it used pooled collections.RazorSyntaxTree.Diagnostics
.