Optimise ToArray for list source
This commit is contained in:
@@ -800,6 +800,14 @@ namespace Newtonsoft.Json.Utilities.LinqBridge
|
|||||||
public static TSource[] ToArray<TSource>(
|
public static TSource[] ToArray<TSource>(
|
||||||
this IEnumerable<TSource> source)
|
this IEnumerable<TSource> source)
|
||||||
{
|
{
|
||||||
|
IList<TSource> ilist = source as IList<TSource>;
|
||||||
|
if (ilist != null)
|
||||||
|
{
|
||||||
|
TSource[] array = new TSource[ilist.Count];
|
||||||
|
ilist.CopyTo(array, 0);
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
return source.ToList().ToArray();
|
return source.ToList().ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user