Beispiel #1
0
        private void EmitStringSwitch(LOLMethod lm, ILGenerator gen)
        {
            LocalBuilder loc = lm.GetTempLocal(gen, typeof(string));

            gen.Emit(OpCodes.Stloc, loc);
            EmitSwitchTree(lm, gen, 0, sortedCases.Length, loc, delegate(ILGenerator ig, Case c)
            {
                ig.Emit(OpCodes.Ldstr, (string)c.name);
                ig.EmitCall(OpCodes.Call, typeof(string).GetMethod("Compare", BindingFlags.Public | BindingFlags.Static, null, new Type[] { typeof(string), typeof(string) }, null), null);
            });
            lm.ReleaseTempLocal(loc);
        }
Beispiel #2
0
 private void EmitIntegerSwitch(LOLMethod lm, ILGenerator gen)
 {
     if (sortedCases.Length * 2 >= (((int)sortedCases[sortedCases.Length - 1].name) - ((int)sortedCases[0].name)))
     {
         //Switch is compact, emit a jump table
         EmitIntegerJumpTable(lm, gen);
     }
     else
     {
         //Switch is not compact - emit a binary tree
         LocalBuilder loc = lm.GetTempLocal(gen, typeof(int));
         gen.Emit(OpCodes.Stloc, loc);
         EmitSwitchTree(lm, gen, 0, sortedCases.Length, loc, delegate(ILGenerator ig, Case c)
         {
             ig.Emit(OpCodes.Ldc_I4, (int)c.name);
             ig.Emit(OpCodes.Sub);
         });
         lm.ReleaseTempLocal(loc);
     }
 }