From 739433047a856697728ca7e39f4cba5faea28f04 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Sun, 10 Apr 2016 21:26:54 +1200 Subject: [PATCH] -XmlNodeConverter perf tweak --- Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs b/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs index 517a06ea..438bb0f1 100644 --- a/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs +++ b/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs @@ -258,7 +258,7 @@ namespace Newtonsoft.Json.Converters // cache results to prevent multiple reads which kills perf in large documents if (_childNodes == null) { - _childNodes = new List(); + _childNodes = new List(_node.ChildNodes.Count); foreach (XmlNode childNode in _node.ChildNodes) { _childNodes.Add(WrapNode(childNode)); @@ -297,7 +297,7 @@ namespace Newtonsoft.Json.Converters // cache results to prevent multiple reads which kills perf in large documents if (_attributes == null) { - _attributes = new List(); + _attributes = new List(_node.Attributes.Count); foreach (XmlAttribute attribute in _node.Attributes) { _attributes.Add(WrapNode(attribute)); @@ -777,6 +777,7 @@ namespace Newtonsoft.Json.Converters internal class XObjectWrapper : IXmlNode { + private static readonly List EmptyChildNodes = new List(); private readonly XObject _xmlObject; public XObjectWrapper(XObject xmlObject) @@ -801,7 +802,7 @@ namespace Newtonsoft.Json.Converters public virtual List ChildNodes { - get { return new List(); } + get { return EmptyChildNodes; } } public virtual List Attributes