Skip to content

Commit

Permalink
Simplified cache construction
Browse files Browse the repository at this point in the history
  • Loading branch information
YohDeadfall committed Feb 11, 2020
1 parent c265f6e commit 19c48b1
Showing 1 changed file with 4 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ public JsonClassInfo(Type type, JsonSerializerOptions options)
case ClassType.Object:
{
CreateObject = options.MemberAccessorStrategy.CreateConstructor(type);
Dictionary<string, JsonPropertyInfo> cache = CreatePropertyCache();
Dictionary<string, JsonPropertyInfo> cache = new Dictionary<string, JsonPropertyInfo>(
Options.PropertyNameCaseInsensitive
? StringComparer.OrdinalIgnoreCase
: StringComparer.Ordinal);

for (Type? currentType = runtimeType; currentType != null; currentType = currentType.BaseType)
{
Expand Down Expand Up @@ -382,22 +385,6 @@ public JsonPropertyInfo GetProperty(ReadOnlySpan<byte> propertyName, ref ReadSta
return info;
}

private Dictionary<string, JsonPropertyInfo> CreatePropertyCache()
{
StringComparer comparer;

if (Options.PropertyNameCaseInsensitive)
{
comparer = StringComparer.OrdinalIgnoreCase;
}
else
{
comparer = StringComparer.Ordinal;
}

return new Dictionary<string, JsonPropertyInfo>(comparer);
}

public JsonPropertyInfo? PolicyProperty { get; private set; }

public MethodInfo? AddItemToObject { get; private set; }
Expand Down

0 comments on commit 19c48b1

Please sign in to comment.