-
Notifications
You must be signed in to change notification settings - Fork 196
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
Remove ItemCollection from CodeRenderingContext #10764
Remove ItemCollection from CodeRenderingContext #10764
Conversation
private static ImmutableArray<TResult> WrapAll<TInner, TResult>(IReadOnlyList<TInner> list, Func<TInner, TResult> createWrapper) | ||
where TInner : class | ||
where TResult : class | ||
{ | ||
var count = list.Count; | ||
if (count == 0) | ||
{ | ||
return ImmutableArray<TResult>.Empty; | ||
} | ||
|
||
using var builder = new PooledArrayBuilder<TResult>(capacity: count); | ||
|
||
for (var i = 0; i < count; i++) | ||
{ | ||
builder.Add(createWrapper(list[i])); | ||
} | ||
|
||
return builder.DrainToImmutable(); | ||
} | ||
|
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.
ℹ️ After converting RazorCSharpDocument
to an ImmutableArray<RazorDiagnostic>
, this method is no longer used.
This change stops pushing the SuppressUniqueIds value into RazorCodeDocument.Items.
This change stops pushing the NewLine value into RazorCodeDocument.Items.
ff182a8
to
34a24b3
Compare
34a24b3
to
6593264
Compare
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 ✅
...Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/RazorDocumentMappingServiceTest.cs
Outdated
Show resolved
Hide resolved
src/Shared/Microsoft.AspNetCore.Razor.Utilities.Shared/EnumExtensions.cs
Show resolved
Hide resolved
...iler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorCodeGenerationOptionsBuilder.cs
Show resolved
Hide resolved
src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorCSharpDocument.cs
Show resolved
Hide resolved
is it worth adding concurrency tests to make sure the usage is thread safe? |
Razor compilation is generally synchronous and |
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.
Compiler side LGTM
it sounds like we don't need to worry about concurrency. I just wanted to double-check. |
Thanks all! |
Because of a dare from @333fred, I'm currently on a crusade to remove
ItemCollection
from the Razor Compiler completely. Previously, I removedItemCollection
fromTagHelperDescriptorProviderContext
(#10720). This time, I'm removing it fromCodeRenderingContext
.It turns out that every
CodeRenderingContext
greedily creates anItemCollection
, though there are only ever two things stored there:CodeWriter
.RazorCodeGenerationOptions
.These two items were really present as a hook that compiler tests could set. However, it's much easier and less wasteful to elevate both items to
RazorCodeGenerationOptions
and make tests set the options directly.I made a few other refactorings as part of this change:
CodeRenderingContext
andDefaultCodeRenderingContext
RazorCSharpDocument
andDefaultRazorCSharpDocument
,RazorCodeGenerationOptions
andDefaultRazorCodeGenerationOptions
RazorCodeGenerationOptionsBuilder
andDefaultRazorCodeGenerationOptionsBuilder
.RazorCodeGenerationOptions
and introducedRazorCodeGenerationOptionsFlags
to track its boolean fields.RazorCSharpDocument
and unified its collections onImmutableArray<>
rather thanIReadOnlyList<>
.CodeRenderingContext
.Note: I was careful with my commit history, and it should be clean enough to review commit-by-commit if that's your preference.