hi @all,
I have these two getter:
public ArrayList I1
{
get
{
if (i1 == null)
{
i1 = new ArrayList();
}
return i1;
}
}
public ArrayList I2
{
get
{
i2 = i2 ?? new ArrayList();
return i2;
}
}
It seems to me, that the MSIL output for the second getter is the
shorter one. But is it also the faster one?
--
.method public hidebysig specialname instance class
[mscorlib]System.Collections.ArrayList
get_I1() cil managed
{
// Code size 41 (0x29)
.maxstack 2
.locals init ([0] class [mscorlib]System.Collections.ArrayList
CS$1$0000,
[1] bool CS$4$0001)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldfld class [mscorlib]System.Collections.ArrayList
ConsoleApplication1.Test::i1
IL_0007: ldnull
IL_0008: ceq
IL_000a: ldc.i4.0
IL_000b: ceq
IL_000d: stloc.1
IL_000e: ldloc.1
IL_000f: brtrue.s IL_001e
IL_0011: nop
IL_0012: ldarg.0
IL_0013: newobj instance void
[mscorlib]System.Collections.ArrayList::.ctor()
IL_0018: stfld class [mscorlib]System.Collections.ArrayList
ConsoleApplication1.Test::i1
IL_001d: nop
IL_001e: ldarg.0
IL_001f: ldfld class [mscorlib]System.Collections.ArrayList
ConsoleApplication1.Test::i1
IL_0024: stloc.0
IL_0025: br.s IL_0027
IL_0027: ldloc.0
IL_0028: ret
} // end of method Test::get_I1
.method public hidebysig specialname instance class
[mscorlib]System.Collections.ArrayList
get_I2() cil managed
{
// Code size 33 (0x21)
.maxstack 3
.locals init ([0] class [mscorlib]System.Collections.ArrayList
CS$1$0000)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldarg.0
IL_0003: ldfld class [mscorlib]System.Collections.ArrayList
ConsoleApplication1.Test::i2
IL_0008: dup
IL_0009: brtrue.s IL_0011
IL_000b: pop
IL_000c: newobj instance void
[mscorlib]System.Collections.ArrayList::.ctor()
IL_0011: stfld class [mscorlib]System.Collections.ArrayList
ConsoleApplication1.Test::i2
IL_0016: ldarg.0
IL_0017: ldfld class [mscorlib]System.Collections.ArrayList
ConsoleApplication1.Test::i2
IL_001c: stloc.0
IL_001d: br.s IL_001f
IL_001f: ldloc.0
IL_0020: ret
} // end of method Test::get_I2
--
mfG
--stefan <--