xpo*_*ort -1 c# compiler-construction programming-languages language-design lexical-analysis
如果您被迫简化可用于循环的C#关键字,请只选择一个要保留的关键字.
您的决定是否有任何绩效考虑?
其实我不知道他们的内在机制,所以在这里我想要采访你们中的人知道细节.但是,某人已经关闭了它.好难过!
我会保留goto-label-if.这就是编译器无论如何都要把一切都变成了什么.流控制的最基本形式是条件分支,用branch/ jumpopcodes完成.
我有关于另一个问题的答案的循环转换的例子.
......这个C#代码......
static void @ifgoto(bool input)
{
label:
if (input)
goto label;
}
static void @while(bool input)
{
while (input) ;
}
static void @for(bool input)
{
for (; input; ) ;
}
Run Code Online (Sandbox Code Playgroud)
...编译到这......
.method private hidebysig static void ifgoto(bool input) cil managed
{
.maxstack 8
L_0000: ldarg.0
L_0001: brtrue.s L_0000
L_0003: ret
}
.method private hidebysig static void while(bool input) cil managed
{
.maxstack 8
L_0000: ldarg.0
L_0001: brtrue.s L_0000
L_0003: ret
}
.method private hidebysig static void for(bool input) cil managed
{
.maxstack 8
L_0000: ldarg.0
L_0001: brtrue.s L_0000
L_0003: ret
}
Run Code Online (Sandbox Code Playgroud)
..为了解释这个......
// load input
L_0000: ldarg.0
// if input is true branch to L_000
L_0001: brtrue.s L_0000
// else return
L_0003: ret
Run Code Online (Sandbox Code Playgroud)