Inlined parameter cache creation (#37320)
authorYoh Deadfall <yoh.deadfall@hotmail.com>
Wed, 3 Jun 2020 16:20:20 +0000 (19:20 +0300)
committerGitHub <noreply@github.com>
Wed, 3 Jun 2020 16:20:20 +0000 (12:20 -0400)
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.Cache.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.cs

index 0e88b3f..520250f 100644 (file)
@@ -48,18 +48,6 @@ namespace System.Text.Json
         // Use an array (instead of List<T>) for highest performance.
         private volatile PropertyRef[]? _propertyRefsSorted;
 
-        public Dictionary<string, JsonParameterInfo> CreateParameterCache(int capacity, JsonSerializerOptions options)
-        {
-            if (options.PropertyNameCaseInsensitive)
-            {
-                return new Dictionary<string, JsonParameterInfo>(capacity, StringComparer.OrdinalIgnoreCase);
-            }
-            else
-            {
-                return new Dictionary<string, JsonParameterInfo>(capacity);
-            }
-        }
-
         public static JsonPropertyInfo AddProperty(PropertyInfo propertyInfo, Type parentClassType, JsonSerializerOptions options)
         {
             JsonIgnoreCondition? ignoreCondition = JsonPropertyInfo.GetAttribute<JsonIgnoreAttribute>(propertyInfo)?.Condition;
index 7c24c67..5e4e284 100644 (file)
@@ -228,7 +228,8 @@ namespace System.Text.Json
         private void InitializeConstructorParameters(Dictionary<string, JsonPropertyInfo> propertyCache, ConstructorInfo constructorInfo)
         {
             ParameterInfo[] parameters = constructorInfo!.GetParameters();
-            Dictionary<string, JsonParameterInfo> parameterCache = CreateParameterCache(parameters.Length, Options);
+            Dictionary<string, JsonParameterInfo> parameterCache = new Dictionary<string, JsonParameterInfo>(
+                parameters.Length, Options.PropertyNameCaseInsensitive ? StringComparer.OrdinalIgnoreCase : null);
 
             foreach (ParameterInfo parameterInfo in parameters)
             {