Improve Expression.Lambda<TDelegate> performance (#32768)
authorVladimir Chirikov <vchirikov@servicetitan.com>
Tue, 25 Feb 2020 21:22:28 +0000 (00:22 +0300)
committerGitHub <noreply@github.com>
Tue, 25 Feb 2020 21:22:28 +0000 (13:22 -0800)
Unnecessary cache call in Expression.Lambda<TDelegate>
(with reflection in worst scenario) has been removed.

Fix #32767

src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/LambdaExpression.cs

index 0d60e32..0e1ead7 100644 (file)
@@ -687,7 +687,11 @@ namespace System.Linq.Expressions
         {
             ReadOnlyCollection<ParameterExpression> parameterList = parameters.ToReadOnly();
             ValidateLambdaArgs(typeof(TDelegate), ref body, parameterList, nameof(TDelegate));
-            return (Expression<TDelegate>)CreateLambda(typeof(TDelegate), body, name, tailCall, parameterList);
+#if FEATURE_COMPILE
+            return Expression<TDelegate>.Create(body, name, tailCall, parameterList);
+#else
+            return ExpressionCreator<TDelegate>.CreateExpressionFunc(body, name, tailCall, parameterList);
+#endif
         }
 
         /// <summary>