Skip to content

Commit 15593e9

Browse files
nareshjoNaresh Joshi
andauthored
Reduce allocations in ProjectItemInstance.CommonConstructor by settin… (#12978)
Co-authored-by: Naresh Joshi <Naresh.Joshi@microsoft.com>
1 parent bef17a5 commit 15593e9

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/Build/Instance/ProjectItemInstance.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,8 @@ private void CommonConstructor(
743743
if (itemDefinitions == null || !useItemDefinitionsWithoutModification)
744744
{
745745
// TaskItems don't have an item type. So for their benefit, we have to lookup and add the regular item definition.
746-
inheritedItemDefinitions = (itemDefinitions == null) ? null : new List<ProjectItemDefinitionInstance>(itemDefinitions);
746+
inheritedItemDefinitions = (itemDefinitions == null) ? null : new List<ProjectItemDefinitionInstance>(itemDefinitions.Count + 1);
747+
((List<ProjectItemDefinitionInstance>)inheritedItemDefinitions)?.AddRange(itemDefinitions);
747748

748749
ProjectItemDefinitionInstance itemDefinition;
749750
if (projectToUse.ItemDefinitions.TryGetValue(itemTypeToUse, out itemDefinition))

0 commit comments

Comments
 (0)