Init dictionary with clear count (#37041)
authorlindexi <lindexi@users.noreply.github.com>
Sat, 30 May 2020 17:13:05 +0000 (01:13 +0800)
committerGitHub <noreply@github.com>
Sat, 30 May 2020 17:13:05 +0000 (10:13 -0700)
src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/CommandLineConfigurationProvider.cs

index a3cb1b9..c3a3ac9 100644 (file)
@@ -137,7 +137,7 @@ namespace Microsoft.Extensions.Configuration.CommandLine
             // The dictionary passed in might be constructed with a case-sensitive comparer
             // However, the keys in configuration providers are all case-insensitive
             // So we check whether the given switch mappings contain duplicated keys with case-insensitive comparer
-            var switchMappingsCopy = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
+            var switchMappingsCopy = new Dictionary<string, string>(switchMappings.Count, StringComparer.OrdinalIgnoreCase);
             foreach (var mapping in switchMappings)
             {
                 // Only keys start with "--" or "-" are acceptable