I thought that property getters in optimized bits would get inlined in .NET but 
looking at 2.0 bits would indicate that they don't.  For example, given this 
source:

class App
{
    private int _field1 = 7;
    private int _field2 = 14;

    static void Main()
    {
        new App().Go();
    }

    public void Go()
    {
        int i1 = _field1;
        int i2 = this.Property;
        int sum = i1 + i2;
    }

    public int Property
    {
        get { return _field2; }
    }
}

The JIT'er generates the following x86 code:

00000000  push        edi  
00000001  push        esi  
00000002  push        ebx  
00000003  push        ebp  
00000004  mov         esi,ecx 
00000006  cmp         dword ptr ds:[00928884h],0 
0000000d  je          00000014 
0000000f  call        78FB10C6 
00000014  xor         ebx,ebx 
00000016  xor         ebp,ebp 
00000018  mov         eax,dword ptr [esi+4]    <<-- direct access to _field1
0000001b  mov         ebx,eax 
0000001d  mov         ecx,esi 
0000001f  call        dword ptr ds:[00929290h] <<-- calls this.Property getter 
00000025  mov         edi,eax 
00000027  mov         ebp,edi 
00000029  nop              
0000002a  pop         ebp  
0000002b  pop         ebx  
0000002c  pop         esi  
0000002d  pop         edi  
0000002e  ret              

Did I just dream that I heard that simple property getters would get inlined by 
the JIT'er to be as fast as a direct field access?

--
Keith Hill
Windows  PowerShell MVP

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to