Formal annotating Code for Optimizations?

Walter Bright newshound1 at digitalmars.com
Fri Jul 18 11:42:14 PDT 2008


Craig Black wrote:
> It'll never be implemented, but it's a good idea.  Along the same lines, 
> (another good idea that'll never be implemented), is to assign a priority to 
> a virtual function.  A higher priority means that the virtual function will 
> be called more.  This allows the compiler to optimize out the function 
> pointer invokation for high-priority virtual functions.

That optimization is not possible, because the compiler doesn't know if 
the virtual function is overridden or not. Bypassing the virtual 
dispatch will break the program.

However, you can tell the compiler a virtual function will not be 
overridden by declaring it 'final', and the compiler will use direct 
rather than virtual dispatch (and it does this already).



More information about the Digitalmars-d mailing list