Advertisement
Guest User

Untitled

a guest
Nov 14th, 2012
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.70 KB | None | 0 0
  1. void Main()
  2. {
  3.     string foo = null;
  4.     string bar = "wooo";
  5.     string foobarIf = useIf(foo,bar);
  6.     string foobarCo = useCoalese(foo,bar);
  7. }
  8.  
  9. string useCoalese(string parameter,string ifNullValue)
  10. {
  11.     return parameter ?? ifNullValue;
  12. }
  13.  
  14. string useIf(string parameter,string ifNullValue)
  15. {
  16.     string retValue = parameter;
  17.     if(retValue == null)
  18.     {
  19.        retValue = ifNullValue;
  20.     }
  21.     return retValue;
  22. }
  23.  
  24. IL W/O Optimizations:
  25.  
  26. IL_0001:  ldnull      
  27. IL_0002:  stloc.0    
  28. IL_0003:  ldstr       "wooo"
  29. IL_0008:  stloc.1    
  30. IL_0009:  ldarg.0    
  31. IL_000A:  ldloc.0    
  32. IL_000B:  ldloc.1    
  33. IL_000C:  call        UserQuery.useIf
  34. IL_0011:  stloc.2    
  35. IL_0012:  ldarg.0    
  36. IL_0013:  ldloc.0    
  37. IL_0014:  ldloc.1    
  38. IL_0015:  call        UserQuery.useCoalese
  39. IL_001A:  stloc.3    
  40.  
  41. useCoalese:
  42. IL_0000:  nop        
  43. IL_0001:  ldarg.1    
  44. IL_0002:  dup        
  45. IL_0003:  brtrue.s    IL_0007
  46. IL_0005:  pop        
  47. IL_0006:  ldarg.2    
  48. IL_0007:  stloc.0    
  49. IL_0008:  br.s        IL_000A
  50. IL_000A:  ldloc.0    
  51. IL_000B:  ret        
  52.  
  53. useIf:
  54. IL_0000:  nop        
  55. IL_0001:  ldarg.1    
  56. IL_0002:  stloc.0    
  57. IL_0003:  ldloc.0    
  58. IL_0004:  ldnull      
  59. IL_0005:  ceq        
  60. IL_0007:  ldc.i4.0    
  61. IL_0008:  ceq        
  62. IL_000A:  stloc.2    
  63. IL_000B:  ldloc.2    
  64. IL_000C:  brtrue.s    IL_0012
  65. IL_000E:  nop        
  66. IL_000F:  ldarg.2    
  67. IL_0010:  stloc.0    
  68. IL_0011:  nop        
  69. IL_0012:  ldloc.0    
  70. IL_0013:  stloc.1    
  71. IL_0014:  br.s        IL_0016
  72. IL_0016:  ldloc.1    
  73. IL_0017:  ret        
  74.  
  75.  
  76.  
  77. IL WITH Optimizations:
  78.  
  79.  
  80. IL_0001:  ldnull      
  81. IL_0002:  stloc.0    
  82. IL_0003:  ldstr       "wooo"
  83. IL_0008:  stloc.1    
  84. IL_0009:  ldarg.0    
  85. IL_000A:  ldloc.0    
  86. IL_000B:  ldloc.1    
  87. IL_000C:  call        UserQuery.useIf
  88. IL_0011:  stloc.2    
  89. IL_0012:  ldarg.0    
  90. IL_0013:  ldloc.0    
  91. IL_0014:  ldloc.1    
  92. IL_0015:  call        UserQuery.useCoalese
  93. IL_001A:  stloc.3    
  94.  
  95. useCoalese:
  96. IL_0000:  nop        
  97. IL_0001:  ldarg.1    
  98. IL_0002:  dup        
  99. IL_0003:  brtrue.s    IL_0007
  100. IL_0005:  pop        
  101. IL_0006:  ldarg.2    
  102. IL_0007:  stloc.0    
  103. IL_0008:  br.s        IL_000A
  104. IL_000A:  ldloc.0    
  105. IL_000B:  ret        
  106.  
  107. useIf:
  108. IL_0000:  nop        
  109. IL_0001:  ldarg.1    
  110. IL_0002:  stloc.0    
  111. IL_0003:  ldloc.0    
  112. IL_0004:  ldnull      
  113. IL_0005:  ceq        
  114. IL_0007:  ldc.i4.0    
  115. IL_0008:  ceq        
  116. IL_000A:  stloc.2    
  117. IL_000B:  ldloc.2    
  118. IL_000C:  brtrue.s    IL_0012
  119. IL_000E:  nop        
  120. IL_000F:  ldarg.2    
  121. IL_0010:  stloc.0    
  122. IL_0011:  nop        
  123. IL_0012:  ldloc.0    
  124. IL_0013:  stloc.1    
  125. IL_0014:  br.s        IL_0016
  126. IL_0016:  ldloc.1    
  127. IL_0017:  ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement