-
-
Notifications
You must be signed in to change notification settings - Fork 11
Closed
Labels
💗 good first featurea feature that is relatively easy to implementa feature that is relatively easy to implementenhancementNew feature or requestNew feature or request
Description
There are at least 2 potential improvements:
-
Better naming variables used to store the instructions representing the start of code for each
case, i.e, instead of naming themNop_[number], use something likeCaseCode_[index]_[number]orCase_[index]_[number]or similar. This improves code readability -
If there is a
defaultcase, do not emit unreachable code (See code below).
class Foo
{
void Bar(int j)
{
switch(j)
{
case 1: System.Console.WriteLine(1); break;
case 2: System.Console.WriteLine(2); break;
default: System.Console.WriteLine(3); break;
}
}
}//case 2: (condition)
il_Bar_2.Emit(OpCodes.Ldloc, lv_switchCondition_4);
il_Bar_2.Emit(OpCodes.Ldc_I4, 2);
il_Bar_2.Emit(OpCodes.Beq_S, Nop_7);
// Jumps to the *default* handling
il_Bar_2.Emit(OpCodes.Br, Nop_8);
// Unreachable code jumping to the end of the switch. If there's a `default` case, this should not be emitted.
il_Bar_2.Emit(OpCodes.Br, Nop_5);Metadata
Metadata
Assignees
Labels
💗 good first featurea feature that is relatively easy to implementa feature that is relatively easy to implementenhancementNew feature or requestNew feature or request