Reputation: 45475
I have a tight inner loop in my project that calls out to a few helper functions. For maximum performance, these simple functions are declared as:
BOOL isValidPoint(CGPoint point) __attribute__((always_inline));
in my ImageCommon.h file, and implemented as:
inline BOOL isValidPoint(CGPoint point);
in ImageCommon.m. In other words, I always want these functions inlined.
If I call isValidPoint
from other functions in ImageCommon.m, the disassembly output confirms that the function call to isValidPoint
has been wiped out. But if I call this function from another source file, the function call remains in place - it isn't inlined.
Is it possible to inline functions called in one implementation file but defined in another?
Upvotes: 3
Views: 394
Reputation: 16315
Try declaring it 'static inline' instead of just 'inline'. The compiler will then treat it as local to the translation unit and should figure out that it really can inline.
EDIT: Sorry, I didn't see that you had this function defined in a translation unit. The definition will also need to be moved to the .h with 'static inline' to work.
Upvotes: 3
Reputation: 23916
My answer would be that are you following the 90:10 rule of optimization. Basically 90% of programmers dont know what to optimize so they have a 10% chance of guessing the 10% of code they need to optimize (a rip off from some other rule)
Basically do not inline anything - let the compiler do it
Upvotes: -3
Reputation: 8932
If you want your function inlined into other compilation units, the definition of that function will need to be visible to those compilation units (i.e., it'll need to be in the header).
Alternatively, you may be able to fool around with link-time optimisation, depending on which compiler you're using.
Upvotes: 1