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
@@ -72,6 +72,13 @@ namespace Newtonsoft.Json.Utilities.LinqBridge
{ {
CheckNotNull(source, "source"); CheckNotNull(source, "source");
var servesItself = source as IEnumerable<TResult>;
if (servesItself != null
&& (!(servesItself is TResult[]) || servesItself.GetType().GetElementType() == typeof(TResult)))
{
return servesItself;
}
return CastYield<TResult>(source); return CastYield<TResult>(source);
} }