2

Is it posible that the JIT compiler will make a static method inlined?

For exmaple, we have some code:

class A
{
     public static int c(int v)
     {
          return v*2
     }
}
..............
Console.WriteLine(A.c(2));

In wihich circumstances can method public static int c(int v) be inlined by the JIT compiler?

Theodoros Chatzigiannakis
  • 28,773
  • 8
  • 68
  • 104
Ruslan F.
  • 5,498
  • 3
  • 23
  • 42
  • 1
    According to [Can I check if the C# compiler inlined a method call?](http://stackoverflow.com/questions/616779/can-i-check-if-the-c-sharp-compiler-inlined-a-method-call) the C# compiler isn't responsible for this, but the JIT compiler takes care of this. – user247702 Aug 06 '14 at 12:59
  • 1
    What do you mean by inlining in C#? –  Aug 06 '14 at 12:59
  • @Alek Depler I mean that JIT will place IL(byte code) of method right to the place of call. – Ruslan F. Aug 06 '14 at 13:10

2 Answers2

2

As I understand it, the compiler (C# or JIT) may or may not inline for performance at its own discretion, but you can always guarantee that the language will behave as designed. i.e. the side effects of the method, if any (none in this case), will happen before the call to writeline.

McKay
  • 12,334
  • 7
  • 53
  • 76
0

According to this post your answer is Yes.

neleus
  • 2,230
  • 21
  • 36