Optimise LinqBridge.Enumerable.Cast for direct cast available.

(This changes the behaviour to return same type, but framework Linq has
the same optimisation).
This commit is contained in:
Jon Hanna
2017-01-04 14:52:30 +00:00
parent 3ae09a80f0
commit 1829b71255
+8 -1
View File
@@ -72,7 +72,14 @@ namespace Newtonsoft.Json.Utilities.LinqBridge
{
CheckNotNull(source, "source");
return CastYield<TResult>(source);
var servesItself = source as IEnumerable<TResult>;
if (servesItself != null
&& (!(servesItself is TResult[]) || servesItself.GetType().GetElementType() == typeof(TResult)))
{
return servesItself;
}
return CastYield<TResult>(source);
}
private static IEnumerable<TResult> CastYield<TResult>(