-JProperty performance
-Improved property name escape skipping
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json.Utilities;
|
||||
using System.Diagnostics;
|
||||
@@ -36,7 +37,93 @@ namespace Newtonsoft.Json.Linq
|
||||
/// </summary>
|
||||
public class JProperty : JContainer
|
||||
{
|
||||
private readonly List<JToken> _content = new List<JToken>();
|
||||
#region JPropertyList
|
||||
private class JPropertyList : IList<JToken>
|
||||
{
|
||||
internal JToken _token;
|
||||
|
||||
public IEnumerator<JToken> GetEnumerator()
|
||||
{
|
||||
if (_token != null)
|
||||
yield return _token;
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
public void Add(JToken item)
|
||||
{
|
||||
_token = item;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_token = null;
|
||||
}
|
||||
|
||||
public bool Contains(JToken item)
|
||||
{
|
||||
return (_token == item);
|
||||
}
|
||||
|
||||
public void CopyTo(JToken[] array, int arrayIndex)
|
||||
{
|
||||
if (_token != null)
|
||||
array[arrayIndex] = _token;
|
||||
}
|
||||
|
||||
public bool Remove(JToken item)
|
||||
{
|
||||
if (_token == item)
|
||||
{
|
||||
_token = null;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get { return (_token != null) ? 1 : 0; }
|
||||
}
|
||||
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public int IndexOf(JToken item)
|
||||
{
|
||||
return (_token == item) ? 0 : -1;
|
||||
}
|
||||
|
||||
public void Insert(int index, JToken item)
|
||||
{
|
||||
if (index == 0)
|
||||
_token = item;
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
if (index == 0)
|
||||
_token = null;
|
||||
}
|
||||
|
||||
public JToken this[int index]
|
||||
{
|
||||
get { return (index == 0) ? _token : null; }
|
||||
set
|
||||
{
|
||||
if (index == 0)
|
||||
_token = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
private readonly JPropertyList _content = new JPropertyList();
|
||||
private readonly string _name;
|
||||
|
||||
/// <summary>
|
||||
@@ -65,14 +152,14 @@ namespace Newtonsoft.Json.Linq
|
||||
public JToken Value
|
||||
{
|
||||
[DebuggerStepThrough]
|
||||
get { return (_content.Count > 0) ? _content[0] : null; }
|
||||
get { return _content._token; }
|
||||
set
|
||||
{
|
||||
CheckReentrancy();
|
||||
|
||||
JToken newValue = value ?? JValue.CreateNull();
|
||||
|
||||
if (_content.Count == 0)
|
||||
if (_content._token == null)
|
||||
{
|
||||
InsertItem(0, newValue, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user