-Performance

This commit is contained in:
James Newton-King
2012-11-01 20:14:08 +13:00
parent a64334b7e2
commit fac8514ff6
3 changed files with 55 additions and 84 deletions
+18 -24
View File
@@ -39,45 +39,39 @@ namespace Newtonsoft.Json
internal struct JsonPosition
{
internal JsonContainerType Type;
internal int? Position;
internal int Position;
internal string PropertyName;
internal bool HasIndex;
public JsonPosition(JsonContainerType type)
{
Type = type;
HasIndex = TypeHasIndex(type);
Position = -1;
PropertyName = null;
}
internal void WriteTo(StringBuilder sb)
{
switch (Type)
{
case JsonContainerType.Object:
if (PropertyName != null)
{
if (sb.Length > 0)
sb.Append(".");
sb.Append(PropertyName);
}
if (sb.Length > 0)
sb.Append(".");
sb.Append(PropertyName);
break;
case JsonContainerType.Array:
case JsonContainerType.Constructor:
if (Position != null)
{
sb.Append("[");
sb.Append(Position);
sb.Append("]");
}
sb.Append("[");
sb.Append(Position);
sb.Append("]");
break;
}
}
internal bool InsideContainer()
internal static bool TypeHasIndex(JsonContainerType type)
{
switch (Type)
{
case JsonContainerType.Object:
return (PropertyName != null);
case JsonContainerType.Array:
case JsonContainerType.Constructor:
return (Position != null);
}
return false;
return (type == JsonContainerType.Array || type == JsonContainerType.Constructor);
}
internal static string BuildPath(IEnumerable<JsonPosition> positions)