-Reduced allocations of JToken.Path

This commit is contained in:
James Newton-King
2016-03-28 19:26:27 +13:00
parent 3a412e5ab2
commit 795ef28e0a
3 changed files with 41 additions and 15 deletions
+7 -2
View File
@@ -190,9 +190,14 @@ namespace Newtonsoft.Json.Linq
return string.Empty;
}
IList<JToken> ancestors = AncestorsAndSelf().Reverse().ToList();
List<JToken> ancestors = new List<JToken>();
for (JToken current = this; current != null; current = current.Parent)
{
ancestors.Add(current);
}
ancestors.Reverse();
List<JsonPosition> positions = new List<JsonPosition>();
List<JsonPosition> positions = new List<JsonPosition>(ancestors.Count);
for (int i = 0; i < ancestors.Count; i++)
{
JToken current = ancestors[i];