From 7f113ff49a8c7f242009d914901becc365ec0ae0 Mon Sep 17 00:00:00 2001 From: Julian Verdurmen <304NotModified@users.noreply.github.com> Date: Sat, 3 Aug 2019 00:10:49 +0200 Subject: [PATCH] Improve performance of calling ICustomTypeDescriptor.GetProperties --- Src/Newtonsoft.Json/Linq/JObject.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Src/Newtonsoft.Json/Linq/JObject.cs b/Src/Newtonsoft.Json/Linq/JObject.cs index 7bfb525b..34cd887e 100644 --- a/Src/Newtonsoft.Json/Linq/JObject.cs +++ b/Src/Newtonsoft.Json/Linq/JObject.cs @@ -744,13 +744,15 @@ namespace Newtonsoft.Json.Linq PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes) { - PropertyDescriptorCollection descriptors = new PropertyDescriptorCollection(null); - + var propertiesArray = new PropertyDescriptor[Count]; + var i = 0; foreach (KeyValuePair propertyValue in this) { - descriptors.Add(new JPropertyDescriptor(propertyValue.Key)); + propertiesArray[i] = new JPropertyDescriptor(propertyValue.Key); + i++; } + var descriptors = new PropertyDescriptorCollection(propertiesArray); return descriptors; }