-Decreased deserializer stack usage

This commit is contained in:
James Newton-King
2012-05-06 01:43:20 +12:00
parent 2dfd0bc940
commit e4491e5812
5 changed files with 296 additions and 225 deletions
@@ -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;
}