Skip to content

Commit

Permalink
Specify list size in TopologicalSortUtility.CalculateRelationships (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Erarndt authored Mar 4, 2024
1 parent 0d9fe5c commit 7cebd2c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/NuGet.Core/NuGet.Packaging/TopologicalSortUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ private static void CalculateRelationships(ItemDependencyInfo[] packages, Dictio
{
var dependencies = package.DependencyIds ?? Array.Empty<string>();

foreach (var id in dependencies)
for (var i = 0; i < dependencies.Length; i++)
{
var id = dependencies[i];
if (lookup.TryGetValue(id, out var dependencyPackage))
{
// Mark the current package as a parent
Expand All @@ -160,7 +161,7 @@ private static void CalculateRelationships(ItemDependencyInfo[] packages, Dictio
var packageChildren = package.Children;
if (packageChildren == null)
{
packageChildren = new List<ItemDependencyInfo>();
packageChildren = new List<ItemDependencyInfo>(dependencies.Length - i);
package.Children = packageChildren;
}
packageChildren.Add(dependencyPackage);
Expand Down

0 comments on commit 7cebd2c

Please sign in to comment.