Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ TryEmitHashtableSwitch()

bool System.Linq.Expressions.Compiler.LambdaCompiler.TryEmitHashtableSwitch ( SwitchExpression node,
CompilationFlags flags )
inlineprivate

Definition at line 3243 of file LambdaCompiler.cs.

3244 {
3245 if (node.Comparison != CachedReflectionInfo.String_op_Equality_String_String && node.Comparison != CachedReflectionInfo.String_Equals_String_String)
3246 {
3247 return false;
3248 }
3249 int num = 0;
3250 foreach (SwitchCase @case in node.Cases)
3251 {
3252 foreach (Expression testValue in @case.TestValues)
3253 {
3254 if (!(testValue is ConstantExpression))
3255 {
3256 return false;
3257 }
3258 num++;
3259 }
3260 }
3261 if (num < 7)
3262 {
3263 return false;
3264 }
3267 int value = -1;
3268 MethodInfo dictionaryOfStringInt32_Add_String_Int = CachedReflectionInfo.DictionaryOfStringInt32_Add_String_Int32;
3269 int i = 0;
3270 for (int count = node.Cases.Count; i < count; i++)
3271 {
3272 foreach (ConstantExpression testValue2 in node.Cases[i].TestValues)
3273 {
3274 if (testValue2.Value != null)
3275 {
3277 }
3278 else
3279 {
3280 value = i;
3281 }
3282 }
3283 builder.UncheckedAdd(Expression.SwitchCase(node.Cases[i].Body, new TrueReadOnlyCollection<Expression>(Utils.Constant(i))));
3284 }
3285 MemberExpression memberExpression = CreateLazyInitializedField<Dictionary<string, int>>("dictionarySwitch");
3286 Expression dictInit = Expression.Condition(Expression.Equal(memberExpression, Expression.Constant(null, memberExpression.Type)), Expression.Assign(memberExpression, Expression.ListInit(Expression.New(CachedReflectionInfo.DictionaryOfStringInt32_Ctor_Int32, new TrueReadOnlyCollection<Expression>(Utils.Constant(list.Count))), list)), memberExpression);
3287 ParameterExpression parameterExpression = Expression.Variable(typeof(string), "switchValue");
3288 ParameterExpression parameterExpression2 = Expression.Variable(typeof(int), "switchIndex");
3289 BlockExpression node2 = Expression.Block(new TrueReadOnlyCollection<ParameterExpression>(parameterExpression2, parameterExpression), new TrueReadOnlyCollection<Expression>(Expression.Assign(parameterExpression, node.SwitchValue), Expression.IfThenElse(Expression.Equal(parameterExpression, Expression.Constant(null, typeof(string))), Expression.Assign(parameterExpression2, Utils.Constant(value)), Expression.IfThenElse(CallTryGetValue(dictInit, parameterExpression, parameterExpression2), Utils.Empty, Expression.Assign(parameterExpression2, Utils.Constant(-1)))), Expression.Switch(node.Type, parameterExpression2, node.DefaultBody, null, builder.ToReadOnly())));
3290 EmitExpression(node2, flags);
3291 return true;
3292 }
static MethodCallExpression CallTryGetValue(Expression dictInit, ParameterExpression switchValue, ParameterExpression switchIndex)

References System.Linq.Expressions.Expression< TDelegate >.Assign(), System.Linq.Expressions.Expression< TDelegate >.Block(), System.Linq.Expressions.Compiler.LambdaCompiler.CallTryGetValue(), System.Linq.Expressions.Expression< TDelegate >.Condition(), System.Linq.Expressions.Utils.Constant(), System.Linq.Expressions.Expression< TDelegate >.Constant(), System.Linq.count, System.Collections.Generic.Dictionary< TKey, TValue >.Count, System.Linq.Expressions.CachedReflectionInfo.DictionaryOfStringInt32_Add_String_Int32, System.Linq.Expressions.CachedReflectionInfo.DictionaryOfStringInt32_Ctor_Int32, System.Linq.Expressions.Expression< TDelegate >.ElementInit(), System.Linq.Expressions.Compiler.LambdaCompiler.EmitExpression(), System.Linq.Expressions.Utils.Empty, System.Linq.Expressions.Expression< TDelegate >.Equal(), System.Linq.Expressions.Expression< TDelegate >.IfThenElse(), System.list, System.Linq.Expressions.Expression< TDelegate >.ListInit(), System.Linq.Expressions.Expression< TDelegate >.New(), System.Linq.Expressions.CachedReflectionInfo.String_Equals_String_String, System.Linq.Expressions.CachedReflectionInfo.String_op_Equality_String_String, System.Linq.Expressions.Expression< TDelegate >.Switch(), System.Linq.Expressions.Expression< TDelegate >.SwitchCase(), System.value, and System.Linq.Expressions.Expression< TDelegate >.Variable().

Referenced by System.Linq.Expressions.Compiler.LambdaCompiler.EmitSwitchExpression().