-Performance tweaks

This commit is contained in:
James Newton-King
2012-08-12 12:38:10 +12:00
parent f5fec30c2a
commit 81ae0210f9
4 changed files with 17 additions and 21 deletions
+3 -3
View File
@@ -39,7 +39,7 @@ namespace Newtonsoft.Json.Linq
/// </example>
public class JArray : JContainer, IList<JToken>
{
private readonly IList<JToken> _values = new List<JToken>();
private readonly List<JToken> _values = new List<JToken>();
/// <summary>
/// Gets the container's children tokens.
@@ -188,9 +188,9 @@ namespace Newtonsoft.Json.Linq
{
writer.WriteStartArray();
foreach (JToken token in _values)
for (int i = 0; i < _values.Count; i++)
{
token.WriteTo(writer, converters);
_values[i].WriteTo(writer, converters);
}
writer.WriteEndArray();
+1 -1
View File
@@ -36,7 +36,7 @@ namespace Newtonsoft.Json.Linq
public class JConstructor : JContainer
{
private string _name;
private readonly IList<JToken> _values = new List<JToken>();
private readonly List<JToken> _values = new List<JToken>();
/// <summary>
/// Gets the container's children tokens.
+2 -2
View File
@@ -370,9 +370,9 @@ namespace Newtonsoft.Json.Linq
{
writer.WriteStartObject();
foreach (JProperty property in _properties)
for (int i = 0; i < _properties.Count; i++)
{
property.WriteTo(writer, converters);
_properties[i].WriteTo(writer, converters);
}
writer.WriteEndObject();
+11 -15
View File
@@ -511,10 +511,20 @@ namespace Newtonsoft.Json.Linq
/// <param name="converters">A collection of <see cref="JsonConverter"/> which will be used when writing the token.</param>
public override void WriteTo(JsonWriter writer, params JsonConverter[] converters)
{
if (converters != null && converters.Length > 0 && _value != null)
{
JsonConverter matchingConverter = JsonSerializer.GetMatchingConverter(converters, _value.GetType());
if (matchingConverter != null)
{
matchingConverter.WriteJson(writer, _value, new JsonSerializer());
return;
}
}
switch (_valueType)
{
case JTokenType.Comment:
writer.WriteComment(_value.ToString());
writer.WriteComment((_value != null) ? _value.ToString() : null);
return;
case JTokenType.Raw:
writer.WriteRawValue((_value != null) ? _value.ToString() : null);
@@ -525,20 +535,6 @@ namespace Newtonsoft.Json.Linq
case JTokenType.Undefined:
writer.WriteUndefined();
return;
}
JsonConverter matchingConverter;
if (_value != null
&& converters != null
&& converters.Length > 0
&& ((matchingConverter = JsonSerializer.GetMatchingConverter(converters, _value.GetType())) != null))
{
matchingConverter.WriteJson(writer, _value, new JsonSerializer());
return;
}
switch (_valueType)
{
case JTokenType.Integer:
writer.WriteValue(Convert.ToInt64(_value, CultureInfo.InvariantCulture));
return;