-Improved deserialization performance by only tracking property presence when needed

This commit is contained in:
James Newton-King
2012-05-06 13:47:23 +12:00
parent e4491e5812
commit 89ab4c0d1e
3 changed files with 85 additions and 46 deletions
@@ -72,6 +72,36 @@ namespace Newtonsoft.Json.Serialization
/// <value>The parametrized constructor.</value>
public ConstructorInfo ParametrizedConstructor { get; set; }
private bool? _hasRequiredOrDefaultValueProperties;
internal bool HasRequiredOrDefaultValueProperties
{
get
{
if (_hasRequiredOrDefaultValueProperties == null)
{
_hasRequiredOrDefaultValueProperties = false;
if (ItemRequired.GetValueOrDefault(Required.Default) != Required.Default)
{
_hasRequiredOrDefaultValueProperties = true;
}
else
{
foreach (JsonProperty property in Properties)
{
if (property.Required != Required.Default || ((property.DefaultValueHandling & DefaultValueHandling.Populate) == DefaultValueHandling.Populate) && property.Writable)
{
_hasRequiredOrDefaultValueProperties = true;
break;
}
}
}
}
return _hasRequiredOrDefaultValueProperties.Value;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="JsonObjectContract"/> class.
/// </summary>