Skip to content

Commit

Permalink
Remove an unnecessary allocation from RestoreBuilder.ToReferenceItems
Browse files Browse the repository at this point in the history
The nested ToReferenceItem method was creating an ImmutableArray, but not using it. Went ahead and removed that line, and then since that method was only a single line, just pushed it's remaining contents to the caller.

There was a surprising amount of allocations going on in this line, which I happened to find while looking at the solution load section of a speedometer trace. Overall, this was about 0.3% of allocations in this profile.
  • Loading branch information
ToddGrun committed Oct 27, 2024
1 parent 6d0b899 commit 83a81bc
Showing 1 changed file with 1 addition and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,7 @@ public static ProjectRestoreInfo ToProjectRestoreInfo(IImmutableDictionary<strin

static ImmutableArray<ReferenceItem> ToReferenceItems(IImmutableDictionary<string, IImmutableDictionary<string, string>> items)
{
return items.ToImmutableArray(static (key, value) => ToReferenceItem(key, value));

static ReferenceItem ToReferenceItem(string name, IImmutableDictionary<string, string> metadata)
{
var properties = metadata.ToImmutableArray(static (key, value) => new ReferenceProperty(key, value));

return new ReferenceItem(name, metadata);
}
return items.ToImmutableArray(static (name, metadata) => new ReferenceItem(name, metadata));
}
}
}
Expand Down

0 comments on commit 83a81bc

Please sign in to comment.