Inlining methods of published classes inside the lib?

Friedrich W. H. Kossebau kossebau at kde.org
Thu Apr 16 21:48:05 CEST 2009


Hi,

I wonder if the following is worth some investigations. Perhaps one of you 
could do a knowledge-based guess?

There are some classes in a lib which are exported, so they have a private 
data object and no inline methods, as we learned to do. Almost all functions 
are implemented in the private class, the published class just forwards the 
calls, e.g.
	void PublicClass::doSomething( param )
	{
		Q_D( PublicClass )
		d->doSomething( param );
	}
Now these classes and their methods are also used a lot inside the lib. Many 
of these methods would have been marked for inlining due to their small size, 
if their class is not in the public API.

Would it perhaps be useful and would it work on all platforms, to move all 
such methods into another file, named e.g. "class_inline.h", tag them as 
inline there and have these files additionally included by all implementation 
files?

So the given example would be in a file "publicclass_inline.h", have the 
tag "inline" added
	inline void PublicClass::doSomething( param )
	{
		Q_D( PublicClass )
		d->doSomething( param );
	}
and all lib internal cpp files using PublicClass would include not 
only "publicclass.h", but also "publicclass_inline.h" (or just the latter, 
which includes the first one anyway). And it will be included 
by "publicclass.cpp", so the compiler sees the methods implementation for 
that object code bundle at least once.

Questions:
? Are all compilers able to treat methods as inline for some callers and not 
inline for others, as resulting by this approach? Do I remember correctly 
that all inline functions also are added once as simple non-inline method to 
the object code (if tagged as exported)?
? How big is the cost of a method call compared to a inlined, simple function, 
e.g. readonly precalculated data access? So might it have a real effect?
? What measures could be taken to find gain vs. costs, and how?

Thanks for your comments in advance
Friedrich
-- 
Okteta - KDE 4 Hex Editor - http://utils.kde.org/projects/okteta


More information about the Kde-optimize mailing list