www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - inlining with D

reply orgoton <orgoton mindless.com> writes:
With C++ i used the "inline" keyword. How to I instrument the D compiler to
inline a function? If it does this automatically, what are the criteria?
Jan 18 2007
next sibling parent BCS <BCS pathlink.com> writes:
orgoton wrote:
 With C++ i used the "inline" keyword. How to I instrument the D compiler to
 inline a function? 
use the -inline command line flag and DMD will start inlineing functions
 If it does this automatically, what are the criteria?
A quick and dirty way to see what functions /may/ be inlined is to run DMD with the -H flag. This will generate a "header" file (<filename>.di) that has prototypes for some functions and source for others. IIRC the cases with source are candidates for inlineing. I seem to recall it amounts to short functions without ASM blocks or loops. But I'm sure that's not all and I may be wrong on that.
Jan 18 2007
prev sibling parent Sean Kelly <sean f4.ca> writes:
orgoton wrote:
 With C++ i used the "inline" keyword. How to I instrument the D compiler to
 inline a function? If it does this automatically, what are the criteria?
It does this automatically so long as the -inline flag it set when compiling. Any function which has an available implementation at compile-time is a candidate for inlining (ie. excluding a C-style "header" module as an interface for a pre-compiled library). At the moment, DMD will not inline delegates, functions containing loops, or ASM code, but all are eventually candidates with compiler refinements. Sean
Jan 18 2007