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:
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user