-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[StaticWebAssets] Cleanup ApplyCompressionNegotiation.cs and ResolveCompressedAssets.cs #48082
base: main
Are you sure you want to change the base?
Conversation
javiercn
commented
Apr 1, 2025
•
edited
Loading
edited
- Removes LINQ usages.
- Avoids excessive array amortization.
- Reduces allocations
Thanks for your PR, @@javiercn. |
4c1beb7
to
9e1de78
Compare
@@ -115,16 +115,22 @@ public override bool Execute() | |||
// Process the final set of candidate assets, deduplicating assets to be compressed in the same format multiple times and | |||
// generating new a static web asset definition for each compressed item. | |||
var formats = SplitPattern(Formats); | |||
var assetsToCompress = new List<ITaskItem>(); | |||
var assetsToCompress = new ITaskItem[matchingCandidateAssets.Count * formats.Length]; |
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.
Instead of creating a list and having to turn it into an array, we create an array of the max size we expect to hold and return that directly.
This takes advantage of the fact that MSBuild will ignore any item that is null when reading the outputs from a task, which save us from having to reallocate the list and convert it back into an array of contiguous elements