-Decreased deserializer stack usage
This commit is contained in:
@@ -171,14 +171,13 @@ namespace Newtonsoft.Json.Utilities
|
||||
}
|
||||
}
|
||||
|
||||
public static object CreateAndPopulateList(Type listType, Action<IList, bool> populateList)
|
||||
public static IList CreateList(Type listType, out bool isReadOnlyOrFixedSize)
|
||||
{
|
||||
ValidationUtils.ArgumentNotNull(listType, "listType");
|
||||
ValidationUtils.ArgumentNotNull(populateList, "populateList");
|
||||
|
||||
IList list;
|
||||
Type collectionType;
|
||||
bool isReadOnlyOrFixedSize = false;
|
||||
isReadOnlyOrFixedSize = false;
|
||||
|
||||
if (listType.IsArray)
|
||||
{
|
||||
@@ -239,21 +238,6 @@ namespace Newtonsoft.Json.Utilities
|
||||
if (list == null)
|
||||
throw new InvalidOperationException("Cannot create and populate list type {0}.".FormatWith(CultureInfo.InvariantCulture, listType));
|
||||
|
||||
populateList(list, isReadOnlyOrFixedSize);
|
||||
|
||||
// create readonly and fixed sized collections using the temporary list
|
||||
if (isReadOnlyOrFixedSize)
|
||||
{
|
||||
if (listType.IsArray)
|
||||
list = ToArray(((List<object>)list).ToArray(), ReflectionUtils.GetCollectionItemType(listType));
|
||||
else if (ReflectionUtils.InheritsGenericDefinition(listType, typeof(ReadOnlyCollection<>)))
|
||||
list = (IList)ReflectionUtils.CreateInstance(listType, list);
|
||||
}
|
||||
else if (list is IWrappedCollection)
|
||||
{
|
||||
return ((IWrappedCollection) list).UnderlyingCollection;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user