From 16421219086393d5632255b85e52e52feef02b5b Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Fri, 29 May 2020 21:36:46 +0100 Subject: [PATCH 1/4] Expand numberOfPowershellRefAssemblies list capacity --- .../commands/utility/AddType.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs index d504a43a46d..59e7b29c8e2 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs @@ -671,8 +671,8 @@ private void LoadAssemblies(IEnumerable assemblies) private static IEnumerable InitDefaultRefAssemblies() { // Define number of reference assemblies distributed with PowerShell. - // This number is accurate as of PowerShell v7.1.0-preview.1 built with .NET v5.0.100-preview.1.20155.7 - const int numberOfPowershellRefAssemblies = 151; + // This number is accurate as of PowerShell v7.1.0-preview.3 built with .NET v5.0.100-preview.5.20278.13 + const int numberOfPowershellRefAssemblies = 152; const int capacity = numberOfPowershellRefAssemblies + 1; var defaultRefAssemblies = new List(capacity); From 370812dd261273b3bf2e09db6afc08ad388c0754 Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Fri, 29 May 2020 22:34:32 +0100 Subject: [PATCH 2/4] Remove assert --- .../commands/utility/AddType.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs index 59e7b29c8e2..080c7f06486 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs @@ -685,11 +685,6 @@ private static IEnumerable InitDefaultRefAssemblies // Add System.Management.Automation.dll defaultRefAssemblies.Add(MetadataReference.CreateFromFile(typeof(PSObject).Assembly.Location)); - // We want to avoid reallocating the internal array, so we assert if the list capacity has increased. - Diagnostics.Assert( - defaultRefAssemblies.Capacity <= capacity, - $"defaultRefAssemblies was resized because of insufficient initial capacity! A capacity of {defaultRefAssemblies.Count} is required."); - return defaultRefAssemblies; } From aba4d03813502cc3b211c1819be42295b53c299d Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Mon, 1 Jun 2020 22:02:26 +0100 Subject: [PATCH 3/4] Address @iSazonov review --- .../commands/utility/AddType.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs index 080c7f06486..7361e38cb0f 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs @@ -670,11 +670,9 @@ private void LoadAssemblies(IEnumerable assemblies) /// private static IEnumerable InitDefaultRefAssemblies() { - // Define number of reference assemblies distributed with PowerShell. - // This number is accurate as of PowerShell v7.1.0-preview.3 built with .NET v5.0.100-preview.5.20278.13 - const int numberOfPowershellRefAssemblies = 152; + const int maxPowershellRefAssemblies = 160; - const int capacity = numberOfPowershellRefAssemblies + 1; + const int capacity = maxPowershellRefAssemblies + 1; var defaultRefAssemblies = new List(capacity); foreach (string file in Directory.EnumerateFiles(s_netcoreAppRefFolder, "*.dll", SearchOption.TopDirectoryOnly)) @@ -685,6 +683,11 @@ private static IEnumerable InitDefaultRefAssemblies // Add System.Management.Automation.dll defaultRefAssemblies.Add(MetadataReference.CreateFromFile(typeof(PSObject).Assembly.Location)); + // We want to avoid reallocating the internal array, so we assert if the list capacity has increased. + Diagnostics.Assert( + defaultRefAssemblies.Capacity <= capacity, + $"defaultRefAssemblies was resized because of insufficient initial capacity! A capacity of {defaultRefAssemblies.Count} is required."); + return defaultRefAssemblies; } From 558d794720d502efc31623617a92de52cfab9aab Mon Sep 17 00:00:00 2001 From: Ilya Date: Tue, 2 Jun 2020 08:35:25 +0500 Subject: [PATCH 4/4] Update src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs --- .../commands/utility/AddType.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs index 7361e38cb0f..cd908296125 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs @@ -670,6 +670,7 @@ private void LoadAssemblies(IEnumerable assemblies) /// private static IEnumerable InitDefaultRefAssemblies() { + // Define number of reference assemblies distributed with PowerShell. const int maxPowershellRefAssemblies = 160; const int capacity = maxPowershellRefAssemblies + 1;