-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
+11 -7
View File
@@ -225,7 +225,15 @@ namespace Newtonsoft.Json
if (_currentPosition.Type == JsonContainerType.None)
return string.Empty;
return JsonPosition.BuildPath(_stack.Concat(new[] { _currentPosition }));
bool insideContainer = (_currentState != State.ArrayStart
&& _currentState != State.ConstructorStart
&& _currentState != State.ObjectStart);
IEnumerable<JsonPosition> positions = (!insideContainer)
? _stack
: _stack.Concat(new[] {_currentPosition});
return JsonPosition.BuildPath(positions);
}
}
@@ -265,16 +273,12 @@ namespace Newtonsoft.Json
if (_currentPosition.Type == JsonContainerType.None)
{
_currentPosition.Type = value;
_currentPosition = new JsonPosition(value);
}
else
{
_stack.Add(_currentPosition);
JsonPosition state = new JsonPosition
{
Type = value
};
_currentPosition = state;
_currentPosition = new JsonPosition(value);
// this is a little hacky because Depth increases when first property/value is written but only testing here is faster/simpler
if (_maxDepth != null && Depth + 1 > _maxDepth && !_hasExceededMaxDepth)