Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Merge pull request #11821 from bartdesmet/MathPowReflectionCache
Browse files Browse the repository at this point in the history
Math.Pow reflection caching
  • Loading branch information
stephentoub authored Sep 17, 2016
2 parents 46494bb + e5c4cf3 commit bffef76
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Diagnostics;
using System.Dynamic.Utils;
using System.Reflection;
using static System.Linq.Expressions.CachedReflectionInfo;

namespace System.Linq.Expressions
{
Expand Down Expand Up @@ -2874,8 +2875,7 @@ public static BinaryExpression Power(Expression left, Expression right, MethodIn
RequiresCanRead(right, nameof(right));
if (method == null)
{
Type mathType = typeof(System.Math);
method = mathType.GetMethod("Pow", BindingFlags.Static | BindingFlags.Public);
method = Math_Pow_Double_Double;
if (method == null)
{
throw Error.BinaryOperatorNotDefined(ExpressionType.Power, left.Type, right.Type);
Expand Down Expand Up @@ -2929,8 +2929,7 @@ public static BinaryExpression PowerAssign(Expression left, Expression right, Me
RequiresCanRead(right, nameof(right));
if (method == null)
{
Type mathType = typeof(System.Math);
method = mathType.GetMethod("Pow", BindingFlags.Static | BindingFlags.Public);
method = Math_Pow_Double_Double;
if (method == null)
{
throw Error.BinaryOperatorNotDefined(ExpressionType.PowerAssign, left.Type, right.Type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,10 @@ internal static class CachedReflectionInfo
public static MethodInfo Decimal_op_Implicit_Char =>
s_Decimal_op_Implicit_Char ??
(s_Decimal_op_Implicit_Char = typeof(decimal).GetMethod("op_Implicit", new[] { typeof(char) }));

private static MethodInfo s_Math_Pow_Double_Double;
public static MethodInfo Math_Pow_Double_Double =>
s_Math_Pow_Double_Double ??
(s_Math_Pow_Double_Double = typeof(Math).GetMethod(nameof(Math.Pow), new[] { typeof(double), typeof(double) }));
}
}

0 comments on commit bffef76

Please sign in to comment.