From d7fefa853db205b77f2b2bca40fffb1c04055c1e Mon Sep 17 00:00:00 2001 From: Akash Kava <39438041+ackava@users.noreply.github.com> Date: Sun, 9 Feb 2025 17:34:23 +0530 Subject: [PATCH] Methods optimized --- .../LinqExpressions/JSVariableBuilder.cs | 52 ++++++++++--------- .../LinqExpressions/StringSpanBuilder.cs | 3 -- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/YantraJS.Core/LinqExpressions/JSVariableBuilder.cs b/YantraJS.Core/LinqExpressions/JSVariableBuilder.cs index 2e5f610d..4b719e7c 100644 --- a/YantraJS.Core/LinqExpressions/JSVariableBuilder.cs +++ b/YantraJS.Core/LinqExpressions/JSVariableBuilder.cs @@ -2,7 +2,7 @@ using System.Linq; using System.Reflection; using YantraJS.Core; - +using YantraJS.Core.LambdaGen; using Exp = YantraJS.Expressions.YExpression; using Expression = YantraJS.Expressions.YExpression; using ParameterExpression = YantraJS.Expressions.YParameterExpression; @@ -11,43 +11,41 @@ namespace YantraJS.ExpHelper { public class JSVariableBuilder { - static readonly Type type = typeof(JSVariable); - - static readonly ConstructorInfo _New - = type.Constructor(typeof(JSValue), typeof(string)); + //static readonly Type type = typeof(JSVariable); - static readonly ConstructorInfo _NewWithStringSpan - = type.Constructor(typeof(JSValue), StringSpanBuilder.RefType); + //static readonly ConstructorInfo _New + // = type.Constructor(typeof(JSValue), typeof(string)); public static Expression New(Expression value, string name) { - return Expression.New(_New, value, Expression.Constant(name)); + return NewLambdaExpression.NewExpression(() => () => new JSVariable(null as JSValue, "") + , value + , Expression.Constant(name)); + // return Expression.New(_New, value, Expression.Constant(name)); } - public static Expression New(Expression value, in StringSpan name) - { - return Expression.New(_NewWithStringSpan, value, StringSpanBuilder.New(in name)); - } - - - static readonly ConstructorInfo _NewFromException - = type.Constructor(typeof(Exception), typeof(string)); + //static readonly ConstructorInfo _NewFromException + // = type.Constructor(typeof(Exception), typeof(string)); public static Expression NewFromException(Expression value, string name) { - return Expression.New(_NewFromException, value, Expression.Constant(name)); + // return Expression.New(_NewFromException, value, Expression.Constant(name)); + return NewLambdaExpression.NewExpression(() => () => new JSVariable(null as Exception, "") + , value + , Expression.Constant(name)); } - static readonly ConstructorInfo _NewFromArgument - = type.Constructor(ArgumentsBuilder.refType, typeof(int), typeof(string)); - - static readonly PropertyInfo _GlobalValue - = type.Property(nameof(JSVariable.GlobalValue)); + //static readonly ConstructorInfo _NewFromArgument + // = type.Constructor(ArgumentsBuilder.refType, typeof(int), typeof(string)); public static Expression FromArgument(Expression args, int i, string name) { - return Expression.New(_NewFromArgument, args, Expression.Constant(i), Expression.Constant(name)); + return NewLambdaExpression.NewExpression(() => () => new JSVariable(Arguments.Empty, 0, "") + , args + , Expression.Constant(i) + , Expression.Constant(name)); + // return Expression.New(_NewFromArgument, args, Expression.Constant(i), Expression.Constant(name)); } public static Expression FromArgumentOptional(Expression args, int i, Expression optional) @@ -61,12 +59,16 @@ public static Expression FromArgumentOptional(Expression args, int i, Expression public static Expression New(string name) { - return Expression.New(_New, ExpHelper.JSUndefinedBuilder.Value, Expression.Constant(name)); + return NewLambdaExpression.NewExpression(() => () => new JSVariable(null as JSValue, "") + , JSUndefinedBuilder.Value + , Expression.Constant(name)); + // return Expression.New(_New, ExpHelper.JSUndefinedBuilder.Value, Expression.Constant(name)); } public static Expression Property(Expression target) { - return Expression.Property(target, _GlobalValue); + return target.PropertyExpression(() => (x) => x.GlobalValue); + //return Expression.Property(target, _GlobalValue); } } diff --git a/YantraJS.Core/LinqExpressions/StringSpanBuilder.cs b/YantraJS.Core/LinqExpressions/StringSpanBuilder.cs index b534ad62..35a500e5 100644 --- a/YantraJS.Core/LinqExpressions/StringSpanBuilder.cs +++ b/YantraJS.Core/LinqExpressions/StringSpanBuilder.cs @@ -13,9 +13,6 @@ namespace YantraJS.ExpHelper { public static class StringSpanBuilder { - - public static Type RefType = typeof(StringSpan).MakeByRefType(); - // public static Type type = typeof(StringSpan); //private static ConstructorInfo _new =