Skip to content

Commit

Permalink
Methods optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
ackava committed Feb 9, 2025
1 parent 062d765 commit d7fefa8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
52 changes: 27 additions & 25 deletions YantraJS.Core/LinqExpressions/JSVariableBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<JSVariable>(() => () => 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<JSVariable>(() => () => 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<JSVariable>(() => () => 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)
Expand All @@ -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<JSVariable>(() => () => 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<JSVariable, JSValue>(() => (x) => x.GlobalValue);
//return Expression.Property(target, _GlobalValue);
}

}
Expand Down
3 changes: 0 additions & 3 deletions YantraJS.Core/LinqExpressions/StringSpanBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit d7fefa8

Please sign in to comment.