inlining

Lutger Blijdestijn lutger.blijdestijn at gmail.com
Tue Dec 7 04:44:18 PST 2010


Jonathan M Davis wrote:

> On Tuesday 07 December 2010 03:05:28 spir wrote:
>> Hello,
>> 
>> Does dmd inline when appropriate (eg single-line func)? or is there a
>> hint keyword? or what else? Eg how to have this inlined:
>> 
>> private bool isPrecomposedHangulSylable (Code code) {
>>     /** whether code is a precomposed Hangul syllable ;-) */
>>     return (code >= FIRST_HANGUL_SYLLABLE) && (code <=
>> LAST_HANGUL_SYLLABLE); }
> 
> C++ has the inline keyword, and it is used only as a hint to the compiler.
> The compiler is free to follow it or ignore it as it sees fit, so its
> usefulness is debateable. D does _not_ have the inline keyword. It just
> leaves it up to the compiler entirely. Note that the -inline flag enables
> inlining.
> 
> IIRC, no functions which have lazy parameters or include inline assembly
> will ever be inlined. And, of course, if a function is long, the compiler
> is unlikely to choose to inline it (though maybe it would choose to if the
> function is only ever called once - that's up to the inliner).
...
> - Jonathan M Davis

There are some other conditions that prevent inlining, it's best to check 
for it. iirc also functions with loops, delegate and ref parameters cannot 
be inlined for example. I'm not so sure about ref, that may have been 
improved since the last time I checked. Perhaps also for some class of 
delegates, at least ldc supposedly can inline some functions with delegate 
parameters.



More information about the Digitalmars-d-learn mailing list