Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Main()
- {
- string foo = null;
- string bar = "wooo";
- string foobarIf = useIf(foo,bar);
- string foobarCo = useCoalese(foo,bar);
- }
- string useCoalese(string parameter,string ifNullValue)
- {
- return parameter ?? ifNullValue;
- }
- string useIf(string parameter,string ifNullValue)
- {
- string retValue = parameter;
- if(retValue == null)
- {
- retValue = ifNullValue;
- }
- return retValue;
- }
- IL W/O Optimizations:
- IL_0001: ldnull
- IL_0002: stloc.0
- IL_0003: ldstr "wooo"
- IL_0008: stloc.1
- IL_0009: ldarg.0
- IL_000A: ldloc.0
- IL_000B: ldloc.1
- IL_000C: call UserQuery.useIf
- IL_0011: stloc.2
- IL_0012: ldarg.0
- IL_0013: ldloc.0
- IL_0014: ldloc.1
- IL_0015: call UserQuery.useCoalese
- IL_001A: stloc.3
- useCoalese:
- IL_0000: nop
- IL_0001: ldarg.1
- IL_0002: dup
- IL_0003: brtrue.s IL_0007
- IL_0005: pop
- IL_0006: ldarg.2
- IL_0007: stloc.0
- IL_0008: br.s IL_000A
- IL_000A: ldloc.0
- IL_000B: ret
- useIf:
- IL_0000: nop
- IL_0001: ldarg.1
- IL_0002: stloc.0
- IL_0003: ldloc.0
- IL_0004: ldnull
- IL_0005: ceq
- IL_0007: ldc.i4.0
- IL_0008: ceq
- IL_000A: stloc.2
- IL_000B: ldloc.2
- IL_000C: brtrue.s IL_0012
- IL_000E: nop
- IL_000F: ldarg.2
- IL_0010: stloc.0
- IL_0011: nop
- IL_0012: ldloc.0
- IL_0013: stloc.1
- IL_0014: br.s IL_0016
- IL_0016: ldloc.1
- IL_0017: ret
- IL WITH Optimizations:
- IL_0001: ldnull
- IL_0002: stloc.0
- IL_0003: ldstr "wooo"
- IL_0008: stloc.1
- IL_0009: ldarg.0
- IL_000A: ldloc.0
- IL_000B: ldloc.1
- IL_000C: call UserQuery.useIf
- IL_0011: stloc.2
- IL_0012: ldarg.0
- IL_0013: ldloc.0
- IL_0014: ldloc.1
- IL_0015: call UserQuery.useCoalese
- IL_001A: stloc.3
- useCoalese:
- IL_0000: nop
- IL_0001: ldarg.1
- IL_0002: dup
- IL_0003: brtrue.s IL_0007
- IL_0005: pop
- IL_0006: ldarg.2
- IL_0007: stloc.0
- IL_0008: br.s IL_000A
- IL_000A: ldloc.0
- IL_000B: ret
- useIf:
- IL_0000: nop
- IL_0001: ldarg.1
- IL_0002: stloc.0
- IL_0003: ldloc.0
- IL_0004: ldnull
- IL_0005: ceq
- IL_0007: ldc.i4.0
- IL_0008: ceq
- IL_000A: stloc.2
- IL_000B: ldloc.2
- IL_000C: brtrue.s IL_0012
- IL_000E: nop
- IL_000F: ldarg.2
- IL_0010: stloc.0
- IL_0011: nop
- IL_0012: ldloc.0
- IL_0013: stloc.1
- IL_0014: br.s IL_0016
- IL_0016: ldloc.1
- IL_0017: ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement