Skip to content

Commit 843ee18

Browse files
committed
Methods optimized
1 parent 1cf9ab4 commit 843ee18

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

YantraJS.Core/LinqExpressions/JSTemplateStringBuilder.cs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,48 +15,57 @@
1515
using TryExpression = YantraJS.Expressions.YTryCatchFinallyExpression;
1616
using YantraJS.Expressions;
1717
using YantraJS.Core;
18+
using YantraJS.Core.LambdaGen;
19+
using YantraJS.Core.Types;
1820

1921
namespace YantraJS.ExpHelper
2022
{
2123
public class JSTemplateStringBuilder
2224
{
23-
private static Type type = typeof(JSTemplateString);
25+
// private static Type type = typeof(JSTemplateString);
2426

25-
private static ConstructorInfo _new =
26-
type.GetConstructor(new Type[] { typeof(int) });
27+
//private static ConstructorInfo _new =
28+
// type.GetConstructor(new Type[] { typeof(int) });
2729

28-
private static MethodInfo _addQuasi =
29-
type.GetMethod(nameof(JSTemplateString.AddQuasi));
30+
//private static MethodInfo _addQuasi =
31+
// type.GetMethod(nameof(JSTemplateString.AddQuasi));
3032

31-
private static MethodInfo _addExpression =
32-
type.GetMethod(nameof(JSTemplateString.AddExpression));
33+
//private static MethodInfo _addExpression =
34+
// type.GetMethod(nameof(JSTemplateString.AddExpression));
3335

34-
private static MethodInfo _toJSString =
35-
type.GetMethod(nameof(JSTemplateString.ToJSString));
36+
//private static MethodInfo _toJSString =
37+
// type.GetMethod(nameof(JSTemplateString.ToJSString));
3638

37-
private static MethodInfo _addString =
38-
type.PublicMethod(nameof(JSTemplateString.Add), typeof(string));
39+
//private static MethodInfo _addString =
40+
// type.PublicMethod(nameof(JSTemplateString.Add), typeof(string));
3941

40-
private static MethodInfo _addValue =
41-
type.PublicMethod(nameof(JSTemplateString.Add), typeof(JSValue));
42+
//private static MethodInfo _addValue =
43+
// type.PublicMethod(nameof(JSTemplateString.Add), typeof(JSValue));
4244

4345
public static Expression New(IEnumerable<Expression> select, int total)
4446
{
4547
var list = new Sequence<YElementInit>();
46-
var newExp = Expression.New(_new, Expression.Constant(total));
48+
var newExp = NewLambdaExpression.NewExpression<JSTemplateString>(() => () => new JSTemplateString((int)0),
49+
Expression.Constant(total));
50+
// var newExp = Expression.New(_new, Expression.Constant(total));
4751
var en = select.GetEnumerator();
52+
53+
var addStringMethod = TypeQuery.QueryInstanceMethod<JSTemplateString>(() => (x) => x.Add((string)""));
54+
var addValueMethod = TypeQuery.QueryInstanceMethod<JSTemplateString>(() => (x) => x.Add((JSValue)null));
55+
4856
while (en.MoveNext())
4957
{
5058
var current = en.Current;
5159
if (current.NodeType == YExpressionType.Constant)
5260
{
5361
// exp = Expression.Call(exp, _addQuasi, current);
54-
list.Add(YExpression.ElementInit(_addString, current));
62+
list.Add(YExpression.ElementInit(addStringMethod, current));
5563
continue;
5664
}
57-
list.Add(YExpression.ElementInit(_addValue, current));
65+
list.Add(YExpression.ElementInit(addValueMethod, current));
5866
}
59-
return Expression.Call( Expression.ListInit(newExp, list), _toJSString);
67+
return Expression.ListInit(newExp, list)
68+
.CallExpression<JSTemplateString>(() => (x) => x.ToJSString());
6069
}
6170

6271
//public static Expression New(List<string> quasis, IEnumerable<Expression> select)

0 commit comments

Comments
 (0)